-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.spec.ts
81 lines (70 loc) · 2.77 KB
/
table.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
71
72
73
74
75
76
77
78
79
80
81
import db from "./fixtures/db";
import { Table } from "../index";
import { CookbookTable } from "./fixtures/tables";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
describe('table', () => {
const config = {endpoint: 'http://localhost:8000'};
const client = new DynamoDBClient(config);
const CookbookTableConstructor = db.getTable('CookbookTable');
let table: Table
beforeEach(() => {
table = new CookbookTableConstructor(client);
})
describe('attribute definitions', () => {
it('should get attribute definitions from factory table', () => {
const expectedAttributeDefinitions = [
{ AttributeName: 'title', AttributeType: 'S' },
{ AttributeName: 'author', AttributeType: 'S' }
]
const attributeDefinitions = table.toAttributeDefinition();
expect(attributeDefinitions).toMatchObject(expectedAttributeDefinitions);
})
it('should get attribute definitions from table instance', () => {
let t = new CookbookTable()
const expectedAttributeDefinitions = [
{ AttributeName: 'title', AttributeType: 'S' },
{ AttributeName: 'author', AttributeType: 'S' }
]
const attributeDefinitions = t.toAttributeDefinition();
expect(attributeDefinitions).toMatchObject(expectedAttributeDefinitions);
})
})
describe('Create Table', () => {
it('should output CreateCommandInput', () => {
const expectedCommandInput = {
TableName: 'Cookbooks',
AttributeDefinitions: [
{ AttributeName: 'title', AttributeType: 'S' },
{ AttributeName: 'author', AttributeType: 'S' }
],
KeySchema: [
{ AttributeName: 'title', KeyType: 'HASH' },
{ AttributeName: 'author', KeyType: 'RANGE' }
],
ProvisionedThroughput: { ReadCapacityUnits: 1, WriteCapacityUnits: 1 }
}
const createCommandInput = table.toCreateCommandInput();
expect(createCommandInput).toMatchObject(expectedCommandInput)
})
})
it('should getPrimaryKeyDefinition', () => {
const primaryKeyDefinition = table.getPrimaryKeyDefinition();
const expectedDefinition = {
pk: { AttributeName: 'title', AttributeType: 'S' },
sk: { AttributeName: 'author', AttributeType: 'S' }
}
expect(expectedDefinition).toMatchObject(primaryKeyDefinition)
})
it('should get information about existing table', async () => {
table = new CookbookTable(client);
const tableInfo = await table.describe();
expect(tableInfo).toHaveProperty('Table.TableName', 'Cookbooks')
})
it('should return undefined when describing non-existing table', async () => {
table = new CookbookTable(client);
// @ts-ignore
table.name = 'noname';
const tableInfo = await table.describe();
expect(tableInfo).toBe(undefined);
})
})