Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 56 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import {Model, Field, Store, Database, Connection, QueueMessage} from "../src/Jeloquent"; |
||
2 | |||
3 | test('Store can add database', () => { |
||
4 | const store = new Store(); |
||
5 | const database = new Database('default', []); |
||
6 | store.add(database); |
||
7 | store.use('default'); |
||
8 | |||
9 | // is now proxy TODO fix a test |
||
10 | expect(store.database()).toBeInstanceOf(Database); |
||
11 | store.use('none'); |
||
12 | expect(store.database()).toStrictEqual(null); |
||
13 | }); |
||
14 | |||
15 | |||
16 | |||
17 | test('Store can load dataset through connection adapter', async () => { |
||
18 | |||
19 | class MockAdapter { |
||
20 | all(model) { |
||
21 | return new Promise((resolve) => { |
||
22 | const modelData = [ |
||
23 | {id: 1, name: 'test'}, |
||
24 | {id: 2, name: 'test 2'}, |
||
25 | {id: 3, name: 'test 3'}, |
||
26 | {id: 4, name: 'test 4'}, |
||
27 | {id: 5, name: 'test 5'}, |
||
28 | {id: 6, name: 'test 6'}, |
||
29 | ]; |
||
30 | const message = new QueueMessage(model, 'insert', modelData); |
||
31 | resolve(message); |
||
32 | }); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | class User extends Model { |
||
37 | constructor() { |
||
38 | const fields = [ |
||
39 | new Field('id', true), |
||
40 | new Field('name') |
||
41 | ] |
||
42 | super(fields); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | const store = new Store(); |
||
47 | const database = new Database('default', [User]); |
||
48 | const connection = new Connection(new MockAdapter()); |
||
49 | store.add(database); |
||
50 | store.addConnection(connection); |
||
51 | store.use('default'); |
||
52 | await store.connection().load(User); |
||
53 | |||
54 | expect(User.all().length).toStrictEqual(6); |
||
55 | }); |
||
56 | |||
57 |