-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamodb-dataloader.test.ts
63 lines (57 loc) · 1.58 KB
/
dynamodb-dataloader.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
61
62
63
import * as dynamodb from '@aws-sdk/client-dynamodb';
import * as dynamodbLib from '@aws-sdk/lib-dynamodb';
import * as assert from 'node:assert/strict';
import test from 'node:test';
import { DynamodbDataLoader } from './dynamodb-dataloader.js';
const dynamodbClient = new dynamodb.DynamoDBClient({});
const tableName = `TestTable_${Math.random().toString(32).substring(2)}`;
test.before(async () => {
await dynamodbClient.send(new dynamodb.CreateTableCommand({
TableName: tableName,
AttributeDefinitions: [
{ AttributeName: 'pk', AttributeType: 'S' },
{ AttributeName: 'sk', AttributeType: 'B' },
],
KeySchema: [
{ KeyType: 'HASH', AttributeName: 'pk' },
{ KeyType: 'RANGE', AttributeName: 'sk' },
],
BillingMode: 'PAY_PER_REQUEST',
}));
await dynamodb.waitUntilTableExists({
client: dynamodbClient,
maxWaitTime: 60,
}, {
TableName: tableName,
});
await dynamodbClient.send(new dynamodbLib.BatchWriteCommand({
RequestItems: {
[tableName]: [
{
PutRequest: {
Item: {
pk: 'pk1',
sk: Buffer.from('sk1'),
attr: 'attr1',
},
},
}
],
},
}));
});
test.after(async () => {
await dynamodbClient.send(new dynamodb.DeleteTableCommand({
TableName: tableName,
}));
});
await test('dynamodbDataLoader', async () => {
const result: any = await new DynamodbDataLoader().getter.load({
TableName: tableName,
Key: {
pk: 'pk1',
sk: Buffer.from('sk1'),
},
});
assert.equal(result.attr, 'attr1');
});