-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.test.ts
175 lines (151 loc) · 5.45 KB
/
service.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import {ActivityService} from "../src/v1/service/activity.service";
import {ActivityItem} from "../src/v1/models/ActivityItem";
const AWS = require("aws-sdk");
const config = {region: "localhost", endpoint: "http://localhost:8000"};
describe('Query Suite', () => {
beforeAll(async (done) => {
console.log('BeforeAll');
done();
});
test('Query', async (done) => {
const item: ActivityItem = {
partitionKey: "54668-30073-6ad9de2",
};
const db = await new AWS.DynamoDB(config);
const activity = new ActivityService(db);
const response = await activity.getActivityItem(item);
expect(response.items.length).toBeGreaterThanOrEqual(0);
done();
});
test('Query - Pagesize', async (done) => {
const item: ActivityItem = {
partitionKey: "54668-30073-6ad9de2",
startTime: 1111111111111,
pageSize: 5
};
const db = await new AWS.DynamoDB(config);
const activity = new ActivityService(db);
const response = await activity.getActivityItem(item);
expect(response.items.length).toBeGreaterThanOrEqual(0);
expect(response.items.length).toBeLessThanOrEqual(5);
done();
});
test('Query - startTime is not valid', async (done) => {
const item: ActivityItem = {
partitionKey: "54668-30073-6ad9de2",
startTime: 1
};
const db = await new AWS.DynamoDB(config);
const activity = new ActivityService(db);
await activity.getActivityItem(item)
.then()
.catch(error => {
done();
});
});
test('Query - endTime is not valid', async (done) => {
const item: ActivityItem = {
partitionKey: "54668-30073-6ad9de2",
startTime: 1111111111111,
endTime: 1
};
const db = await new AWS.DynamoDB(config);
const activity = new ActivityService(db);
activity.getActivityItem(item)
.then()
.catch(error => {
done();
});
});
test('Query - Range search', async (done) => {
const item: ActivityItem = {
partitionKey: "54668-30073-6ad9de2",
startTime: 1515002351700,
endTime: 1595002351700
};
const db = await new AWS.DynamoDB(config);
const activity = new ActivityService(db);
const response = await activity.getActivityItem(item);
expect(response.items.length).toBeGreaterThanOrEqual(0);
done();
});
test('Query - Range search with Filter', async (done) => {
const item: ActivityItem = {
partitionKey: "54668-30073-6ad9de2",
startTime: 1515002351700,
endTime: 1595002351700,
activityType: "BARK"
};
const db = await new AWS.DynamoDB(config);
const activity = new ActivityService(db);
const response = await activity.getActivityItem(item);
expect(response.items.length).toBeGreaterThanOrEqual(0);
done();
});
test('Query - Range search with Incorrect Filter', async (done) => {
const item: ActivityItem = {
partitionKey: "54668-30073-6ad9de2",
startTime: 1515002351700,
endTime: 1595002351700,
activityType: "XYZ"
};
const db = await new AWS.DynamoDB(config);
const activity = new ActivityService(db);
activity.getActivityItem(item)
.then()
.catch(error => {
done();
});
});
test('Mutation Create', async (done) => {
const item: ActivityItem = {
partitionKey: "54668-30073-6ad9de2",
activityType: "BARK",
actionData: {duration: 34}
};
const db = await new AWS.DynamoDB(config);
const activity = new ActivityService(db);
const response = await activity.createActivityItem(item);
expect(response.items[0].createdAt).toBeTruthy();
done();
});
test('Mutation Create - Fail (Missing activity type)', async (done) => {
const item: ActivityItem = {
partitionKey: "54668-30073-6ad9de2",
actionData: {duration: 34}
};
const db = await new AWS.DynamoDB(config);
const activity = new ActivityService(db);
activity.createActivityItem(item)
.then()
.catch(error => {
done();
});
});
test('Mutation Create - Fail (Absence of long in location)', async (done) => {
const item: ActivityItem = {
partitionKey: "54668-30073-6ad9de2",
activityType: "LOCATION",
actionData: {location: {lat: 34}}
};
const db = await new AWS.DynamoDB(config);
const activity = new ActivityService(db);
activity.createActivityItem(item)
.then()
.catch(error => {
done();
});
});
test('Mutation Delete', async (done) => {
const item: ActivityItem = {
partitionKey: "54668-30073-6ad9de2",
sortKey: "1565084041403_BARK",
};
const db = await new AWS.DynamoDB(config);
const activity = new ActivityService(db);
const response = await activity.deleteActivityItem(item);
expect(response.partitionKey).toBeTruthy();
expect(response.sortKey).toBeTruthy();
done();
});
});