import { test } from '@japa/runner'
import { File, Folder } from '../../../../src/index.js'

test.group('File.updateByMeMeta()', () => {
  test('sets deletedInfo.byMe for the same user', ({ assert }) => {
    const schema = Folder.fromName('s1').toJSON()
    schema.deletedInfo = {
      byMe: false,
      time: 1,
      name: 'a',
      user: 'b',
    }
    File.updateByMeMeta(schema, 'b')
    assert.isTrue(schema.deletedInfo!.byMe)
  })

  test('sets deletedInfo.byMe for the different user', ({ assert }) => {
    const schema = Folder.fromName('s1').toJSON()
    schema.deletedInfo = {
      byMe: false,
      time: 1,
      name: 'a',
      user: 'c',
    }
    File.updateByMeMeta(schema, 'b')
    assert.isFalse(schema.deletedInfo!.byMe)
  })

  test('sets lastModified.byMe for the same user', ({ assert }) => {
    const schema = Folder.fromName('s1').toJSON()
    schema.lastModified = {
      byMe: false,
      time: 1,
      name: 'a',
      user: 'b',
    }
    File.updateByMeMeta(schema, 'b')
    assert.isTrue(schema.lastModified!.byMe)
  })

  test('sets lastModified.byMe for the different user', ({ assert }) => {
    const schema = Folder.fromName('s1').toJSON()
    schema.lastModified = {
      byMe: false,
      time: 1,
      name: 'a',
      user: 'c',
    }
    File.updateByMeMeta(schema, 'b')
    assert.isFalse(schema.lastModified!.byMe)
  })
})
