-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmssql-source.spec.ts
70 lines (63 loc) · 1.98 KB
/
mssql-source.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
59
60
61
62
63
64
65
66
67
68
69
70
import { Job, MssqlProcessor } from '../src';
import { IMssqlDbConnection } from '../src/types';
import * as utils from '../src/utils';
import { CustomDestination } from './helpers';
let db: any = null;
const connection: IMssqlDbConnection = {
user: 'sa',
password: 'Passw0rd*',
server: 'mssql',
database: 'tempdb',
options: {
trustServerCertificate: true,
}
};
describe.each(['tedious', 'msnodesqlv8'])('different drivers', (driverName) => {
beforeEach(async () => {
if (driverName === 'msnodesqlv8') {
connection.driver = await import('mssql/msnodesqlv8');
}
db = await utils.getDb(connection, 'mssql');
await db.query(`DROP TABLE IF EXISTS test`);
await db.query(`CREATE TABLE test
(
id integer
)`);
});
afterEach(async () => {
await utils.closeDbConnection(connection);
})
it(`gets data from mssql using ${driverName} driver`, async () => {
await db.query(`INSERT INTO test (id) values (123)`);
const destination = new CustomDestination({
batchSize: 1,
});
const processor = new MssqlProcessor({
connection,
query: `select id from test`,
});
const job = new Job(processor, [destination]);
await job.run();
expect(destination.getData()).toEqual([{
id: 123,
}]);
});
it(`respects rowLimit using ${driverName} driver`, async () => {
await db.query(`INSERT INTO test (id) values (1), (2), (3), (4)`);
const destination = new CustomDestination();
const processor = new MssqlProcessor({
connection,
query: `select id from test`,
rowLimit: 3,
});
const job = new Job(processor, [destination]);
await job.run();
expect(destination.getData()).toEqual([{
id: 1,
}, {
id: 2,
}, {
id: 3,
}]);
});
});