Skip to content

Commit c18d1a6

Browse files
committed
simplify tests using snapshots
1 parent e139c1e commit c18d1a6

File tree

6 files changed

+287
-90
lines changed

6 files changed

+287
-90
lines changed

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
const config = {
4+
coverageReporters: ['lcov', 'text-summary'],
5+
};
6+
7+
module.exports = config;

package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,5 @@
6363
"prettier --write",
6464
"git add"
6565
]
66-
},
67-
"jest": {
68-
"coverageReporters": [
69-
"lcov",
70-
"text-summary"
71-
]
7266
}
7367
}

test/helpers.js

Lines changed: 8 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ const _query = (client, queries) => {
1212
);
1313
};
1414

15-
const _getTableColumn = (table, column) => {
16-
return table && table.columns.find(({ name }) => name === column);
17-
};
18-
1915
exports.setup = ({
2016
schema,
2117
dialect,
@@ -39,8 +35,6 @@ exports.setup = ({
3935
unique: 'users_u_constraint',
4036
};
4137

42-
const prefix = schema ? `[ ${schema} ] ` : '';
43-
4438
const metalize = new Metalize({ dialect, connectionConfig });
4539

4640
beforeAll(() => {
@@ -84,78 +78,17 @@ exports.setup = ({
8478
return _query(metalize._client, queries);
8579
});
8680

87-
it(`${prefix}reading tables`, async () => {
88-
const result = await metalize.read({ tables: [table] });
89-
const _table = result.tables.get(table);
90-
91-
expect(_table.primaryKey).toBeDefined();
92-
expect(typeof _table.primaryKey.name).toBe('string');
93-
expect(_table.primaryKey).toMatchObject({
94-
columns: ['id'],
95-
});
96-
97-
expect(_table.columns).toHaveLength(5);
98-
99-
expect(_getTableColumn(_table, 'name')).toMatchObject({
100-
type: {
101-
name: isPostgres ? 'character varying' : 'varchar',
102-
length: 255,
103-
},
104-
default: isPostgres ? "'noname'::character varying" : 'noname',
105-
});
106-
107-
expect(_getTableColumn(_table, 'budget')).toMatchObject({
108-
type: {
109-
name: isPostgres ? 'numeric' : 'decimal',
110-
precision: 16,
111-
scale: 3,
112-
},
113-
});
114-
115-
expect(_table.foreignKeys[0]).toBeDefined();
116-
expect(_table.foreignKeys[0]).toMatchObject({
117-
name: _constraintNames.foreignKey,
118-
columns: ['id', 'child'],
119-
references: {
120-
table: childTable,
121-
columns: ['parent', 'id'],
122-
},
123-
onUpdate: 'RESTRICT',
124-
onDelete: 'CASCADE',
125-
});
126-
127-
const ageColumn = _getTableColumn(_table, 'age');
128-
expect(ageColumn).toBeDefined();
129-
if (isPostgres) {
130-
expect(ageColumn.identity).toMatchObject({
131-
start: '100',
132-
min: '100',
133-
max: '9999',
134-
cycle: false,
135-
});
136-
} else {
137-
expect(ageColumn.identity).toBeTruthy();
138-
}
139-
140-
if (isPostgres) {
141-
expect(_table.checks[0]).toBeDefined();
142-
expect(_table.checks[0].name).toEqual(_constraintNames.check);
143-
expect(typeof _table.checks[0].condition).toEqual('string');
144-
}
81+
it(`[ reading tables ]`, function() {
82+
return expect(
83+
metalize.read({ tables: [table] })
84+
).resolves.toMatchSnapshot();
14585
});
14686

14787
if (isPostgres) {
148-
it(`${prefix}reading sequences`, async () => {
149-
const result = await metalize.read({ sequences: [sequence] });
150-
const _sequence = result.sequences.get(sequence);
151-
152-
expect(_sequence).toMatchObject({
153-
start: '100',
154-
min: '100',
155-
max: '9999',
156-
increment: '1',
157-
cycle: true,
158-
});
88+
it(`[ reading sequences ]`, function() {
89+
return expect(
90+
metalize.read({ sequences: [sequence] })
91+
).resolves.toMatchSnapshot();
15992
});
16093
}
16194

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`'mysql' dialect [ reading tables ] 1`] = `
4+
Object {
5+
"sequences": Map {},
6+
"tables": Map {
7+
"metalize_schema.users" => Object {
8+
"columns": Array [
9+
Object {
10+
"default": null,
11+
"identity": false,
12+
"name": "id",
13+
"nullable": false,
14+
"type": Object {
15+
"name": "bigint",
16+
"precision": 19,
17+
"raw": "bigint",
18+
"scale": 0,
19+
},
20+
},
21+
Object {
22+
"default": "noname",
23+
"identity": false,
24+
"name": "name",
25+
"nullable": true,
26+
"type": Object {
27+
"length": 255,
28+
"name": "varchar",
29+
"raw": "varchar(255)",
30+
},
31+
},
32+
Object {
33+
"default": null,
34+
"identity": false,
35+
"name": "budget",
36+
"nullable": true,
37+
"type": Object {
38+
"name": "decimal",
39+
"precision": 16,
40+
"raw": "decimal(16,3)",
41+
"scale": 3,
42+
},
43+
},
44+
Object {
45+
"default": null,
46+
"identity": true,
47+
"name": "age",
48+
"nullable": false,
49+
"type": Object {
50+
"name": "bigint",
51+
"precision": 19,
52+
"raw": "bigint",
53+
"scale": 0,
54+
},
55+
},
56+
Object {
57+
"default": null,
58+
"identity": false,
59+
"name": "child",
60+
"nullable": true,
61+
"type": Object {
62+
"name": "bigint",
63+
"precision": 19,
64+
"raw": "bigint",
65+
"scale": 0,
66+
},
67+
},
68+
],
69+
"foreignKeys": Array [
70+
Object {
71+
"columns": Array [
72+
"id",
73+
"child",
74+
],
75+
"match": "NONE",
76+
"name": "users_f_constraint",
77+
"onDelete": "CASCADE",
78+
"onUpdate": "RESTRICT",
79+
"references": Object {
80+
"columns": Array [
81+
"parent",
82+
"id",
83+
],
84+
"table": "metalize_schema.users_child",
85+
},
86+
},
87+
],
88+
"indexes": Array [
89+
Object {
90+
"columns": Array [
91+
"id",
92+
"child",
93+
],
94+
"name": "index_name",
95+
},
96+
Object {
97+
"columns": Array [
98+
"age",
99+
],
100+
"name": "age_index",
101+
},
102+
],
103+
"primaryKey": Object {
104+
"columns": Array [
105+
"id",
106+
],
107+
"name": "PRIMARY",
108+
},
109+
"unique": Array [
110+
Object {
111+
"columns": Array [
112+
"name",
113+
"age",
114+
],
115+
"name": "users_u_constraint",
116+
},
117+
],
118+
},
119+
},
120+
}
121+
`;
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`'postgres' dialect [ reading sequences ] 1`] = `
4+
Object {
5+
"sequences": Map {
6+
"MetalizeSchema.users_seq" => Object {
7+
"cycle": true,
8+
"increment": "1",
9+
"max": "9999",
10+
"min": "100",
11+
"start": "100",
12+
},
13+
},
14+
"tables": Map {},
15+
}
16+
`;
17+
18+
exports[`'postgres' dialect [ reading tables ] 1`] = `
19+
Object {
20+
"sequences": Map {},
21+
"tables": Map {
22+
"MetalizeSchema.users" => Object {
23+
"checks": Array [
24+
Object {
25+
"condition": "age > 21",
26+
"name": "users_c_constraint",
27+
},
28+
],
29+
"columns": Array [
30+
Object {
31+
"collate": null,
32+
"default": null,
33+
"identity": null,
34+
"name": "id",
35+
"nullable": false,
36+
"type": Object {
37+
"name": "bigint",
38+
"precision": 64,
39+
"raw": "bigint",
40+
"scale": 0,
41+
},
42+
},
43+
Object {
44+
"collate": null,
45+
"default": null,
46+
"identity": null,
47+
"name": "budget",
48+
"nullable": true,
49+
"type": Object {
50+
"name": "numeric",
51+
"precision": 16,
52+
"raw": "numeric(16,3)",
53+
"scale": 3,
54+
},
55+
},
56+
Object {
57+
"collate": null,
58+
"default": null,
59+
"identity": null,
60+
"name": "child",
61+
"nullable": true,
62+
"type": Object {
63+
"name": "bigint",
64+
"precision": 64,
65+
"raw": "bigint",
66+
"scale": 0,
67+
},
68+
},
69+
Object {
70+
"collate": null,
71+
"default": "'noname'::character varying",
72+
"identity": null,
73+
"name": "name",
74+
"nullable": true,
75+
"type": Object {
76+
"length": 255,
77+
"name": "character varying",
78+
"raw": "character varying(255)",
79+
},
80+
},
81+
Object {
82+
"collate": null,
83+
"default": null,
84+
"identity": Object {
85+
"cycle": false,
86+
"generation": "ALWAYS",
87+
"increment": "5",
88+
"max": "9999",
89+
"min": "100",
90+
"start": "100",
91+
},
92+
"name": "age",
93+
"nullable": false,
94+
"type": Object {
95+
"name": "smallint",
96+
"precision": 16,
97+
"raw": "smallint",
98+
"scale": 0,
99+
},
100+
},
101+
],
102+
"foreignKeys": Array [
103+
Object {
104+
"columns": Array [
105+
"id",
106+
"child",
107+
],
108+
"match": "SIMPLE",
109+
"name": "users_f_constraint",
110+
"onDelete": "CASCADE",
111+
"onUpdate": "RESTRICT",
112+
"references": Object {
113+
"columns": Array [
114+
"parent",
115+
"id",
116+
],
117+
"table": "MetalizeSchema.users_child",
118+
},
119+
},
120+
],
121+
"indexes": Array [
122+
Object {
123+
"columns": Array [
124+
"id",
125+
"child",
126+
],
127+
"name": "index_name",
128+
},
129+
],
130+
"name": "MetalizeSchema.users",
131+
"primaryKey": Object {
132+
"columns": Array [
133+
"id",
134+
],
135+
"name": "users_pkey",
136+
},
137+
"unique": Array [
138+
Object {
139+
"columns": Array [
140+
"name",
141+
"age",
142+
],
143+
"name": "users_u_constraint",
144+
},
145+
],
146+
},
147+
},
148+
}
149+
`;

0 commit comments

Comments
 (0)