-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbase-repository.spec.ts
58 lines (44 loc) · 1.32 KB
/
base-repository.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { BaseRepository } from './base-repository'
interface MyEntity {
id: string
name: string
}
class MyRepository extends BaseRepository<MyEntity> {}
const row: MyEntity = { id: '1', name: 'my name' }
describe('BaseRepository', () => {
let repository: BaseRepository<MyEntity>
beforeEach(() => {
repository = new MyRepository()
})
test('updateOrCreate()', () => {
repository.updateOrCreate('1', row)
expect(repository).toMatchSnapshot()
repository.updateOrCreate('1', { id: '1', name: 'my new name' })
expect(repository).toMatchSnapshot()
})
test('create()', () => {
repository.create(row)
expect(repository).toMatchSnapshot()
})
test('update()', () => {
repository.create(row)
repository.update('1', { id: '1', name: 'updated' })
expect(repository).toMatchSnapshot()
})
test('delete()', () => {
repository.create(row)
repository.delete('1')
expect(repository.findAll()).toHaveLength(0)
})
test('find()', () => {
expect(repository.find('1')).toBeUndefined()
repository.create(row)
expect(repository.find('1')).toEqual(row)
})
test('findAll()', () => {
expect(repository.findAll()).toHaveLength(0)
repository.create(row)
repository.create({ id: '2', name: 'other' })
expect(repository.findAll()).toMatchSnapshot()
})
})