forked from zestlabs-io/zest-js-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataAPI.test.ts
60 lines (50 loc) · 1.95 KB
/
DataAPI.test.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
import { DistrConfigServiceApiHMAC } from '../../src/API';
import { PoolDataServiceApiHMAC } from '../../src/API';
import { DistrconfigPoolType } from '../../src/openapi';
beforeAll(async (done) => {
const cloudKey = process.env.ZEST_KEY || '';
const cloudSecret = process.env.ZEST_SECRET || '';
distrAPI = new DistrConfigServiceApiHMAC(baseUrl, cloudKey, cloudSecret);
dataAPI = new PoolDataServiceApiHMAC(baseUrl, cloudKey, cloudSecret);
const poolCreateResp = await distrAPI.createPool({
id: poolId,
poolType: DistrconfigPoolType.GLOBAL,
pkExtractExpression: '$.pk',
tagExtractExpression: '$.locality',
});
expect(poolCreateResp.status).toBe(200);
done()
});
afterAll(async (done) => {
const resDel = await distrAPI.deletePool(poolId);
expect(resDel.status).toBe(200);
done();
});
const poolId = 'test_pool_data_1';
const baseUrl = 'https://dev.zestlabs.cloud';
var distrAPI: DistrConfigServiceApiHMAC
var dataAPI: PoolDataServiceApiHMAC
test('Create/Update few records', async () => {
const createResp = await dataAPI.bulkCreate(poolId,
[{ pk: 'customer1', locality: 'loc1' } as any,
{ pk: 'customer2', locality: 'loc1' } as any,
{ pk: 'customer3', locality: 'loc2' } as any]);
expect(createResp.status).toBe(200);
const readCust1 = await dataAPI.get(poolId, 'customer1');
expect(readCust1.status).toBe(200);
// console.log('Got customer', readCust1.body);
const cust1 = readCust1.data as any;
expect(cust1.locality).toBe('loc1')
const updateResp = await dataAPI.bulkUpdate(poolId,
[{ pk: 'customer1', locality: 'loc2' } as any,
{ pk: 'customer2', locality: 'loc2' } as any,
{ pk: 'customer3', locality: 'loc1' } as any]);
expect(updateResp.status).toBe(200);
const listResp = await dataAPI.list(poolId, 10, 0);
expect(updateResp.status).toBe(200);
// const list = listResp.data;
// if (list.rows)
// expect(list.rows.length).toBe(3);
// else
// fail(new Error(JSON.stringify(list)))
});