Completed
Push — master ( 5f62fb...1a8fc1 )
by Mark
16s queued 12s
created

MockAdapter   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 14
rs 10
c 0
b 0
f 0
wmc 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A all 0 12 1
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
    expect(store.database()).toBeInstanceOf(Database);
10
    store.use('none');
11
    expect(store.database()).toStrictEqual(null);
12
});
13
14
15
16
test('Store can load dataset through connection adapter', async () => {
17
18
    class MockAdapter {
19
        all(model) {
20
            return new Promise((resolve) => {
21
                const modelData = [
22
                    {id: 1, name: 'test'},
23
                    {id: 2, name: 'test 2'},
24
                    {id: 3, name: 'test 3'},
25
                    {id: 4, name: 'test 4'},
26
                    {id: 5, name: 'test 5'},
27
                    {id: 6, name: 'test 6'},
28
                ];
29
                const message = new QueueMessage(model, 'insert', modelData);
30
                resolve(message);
31
            });
32
        }
33
    }
34
35
    class User extends Model {
36
        constructor() {
37
            const fields = [
38
                new Field('id', true),
39
                new Field('name')
40
            ]
41
            super(fields);
42
        }
43
    }
44
45
    const store = new Store();
46
    const database = new Database('default', [User]);
47
    const connection = new Connection(new MockAdapter());
48
    store.add(database);
49
    store.addConnection(connection);
50
    store.use('default');
51
    await store.connection().load(User);
52
53
    expect(User.all().length).toStrictEqual(6);
54
});
55
56