53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import assert from 'assert'
|
|
import { Entity } from '../app/entity'
|
|
import { Storage } from '../app/storage'
|
|
import { Repo } from '../app/repo'
|
|
import { Data } from '../app/data'
|
|
import { MapStorage } from './storage.test'
|
|
import { ItemData } from './data.test'
|
|
|
|
class Item extends Entity<ItemData> {
|
|
_getVO(): ItemData {
|
|
return new ItemData()
|
|
}
|
|
|
|
protected _data: ItemData
|
|
|
|
getA(): number {
|
|
return this._data.a
|
|
}
|
|
|
|
getC(): { d: number; e?: number } {
|
|
return this._data.c
|
|
}
|
|
|
|
_getRepo(storage: Storage): ItemRepository {
|
|
return new ItemRepository(storage)
|
|
}
|
|
}
|
|
|
|
class ItemRepository extends Repo<Item> {
|
|
Name() {
|
|
return 'items'
|
|
}
|
|
|
|
Entity() {
|
|
return new Item()
|
|
}
|
|
}
|
|
|
|
describe('ItemRepository', () => {
|
|
describe('map storage save', () => {
|
|
const storage = new MapStorage('')
|
|
const repo = new ItemRepository(storage)
|
|
|
|
it('should return entity', async () => {
|
|
const dt = Data.assign(new ItemData(), { a: 1, b: 2, c: { d: 3 } })
|
|
const item = new Item(dt as ItemData)
|
|
await repo.save(item)
|
|
const itemFromRepo = await repo.findById('1')
|
|
assert.notStrictEqual(item.data, itemFromRepo.data)
|
|
})
|
|
})
|
|
})
|