Skip to content

Commit fd93e17

Browse files
committed
More functional test refactoring
1 parent 7fd4a18 commit fd93e17

15 files changed

+247
-249
lines changed

test/local/functional/domain/github/crawler/crawlInstallations.test.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import {
77
import example_personal_account_installation from '../../../../../examples/github/personal-account/api/installation.json'
88
import example_org_installation from '../../../../../examples/github/org/api/installation.json'
99
import { crawlInstallations } from '../../../../../../src/app/domain/github/crawler/crawlInstallations'
10+
import {
11+
expectPut,
12+
expectPutsLength
13+
} from '../../../../../testSupport/fakes/dynamoDB/fakeDynamoDBInterfaceExpectations'
14+
import { expectedPutGithubInstallation } from '../../../../../testSupport/fakes/tableRecordExpectedWrites'
1015

1116
test('app-crawler-for-personal-account-installation', async () => {
1217
// A
@@ -21,16 +26,8 @@ test('app-crawler-for-personal-account-installation', async () => {
2126
const result = await crawlInstallations(appState)
2227

2328
// A
24-
expect(appState.dynamoDB.puts.length).toEqual(1)
25-
expect(appState.dynamoDB.puts[0]).toEqual({
26-
Item: {
27-
PK: 'ACCOUNT#162360409',
28-
_et: 'githubInstallation',
29-
_lastUpdated: '2024-02-02T19:00:00.000Z',
30-
...testPersonalInstallation
31-
},
32-
TableName: 'fakeGithubInstallationsTable'
33-
})
29+
expectPutsLength(appState).toEqual(1)
30+
expectPut(appState).toEqual(expectedPutGithubInstallation(testPersonalInstallation))
3431
expect(result).toEqual([testPersonalInstallation])
3532
})
3633

@@ -47,15 +44,7 @@ test('app-crawler-for-org-installation', async () => {
4744
const result = await crawlInstallations(appState)
4845

4946
// A
50-
expect(appState.dynamoDB.puts.length).toEqual(1)
51-
expect(appState.dynamoDB.puts[0]).toEqual({
52-
Item: {
53-
PK: 'ACCOUNT#162483619',
54-
_et: 'githubInstallation',
55-
_lastUpdated: '2024-02-02T19:00:00.000Z',
56-
...testOrgInstallation
57-
},
58-
TableName: 'fakeGithubInstallationsTable'
59-
})
47+
expectPutsLength(appState).toEqual(1)
48+
expectPut(appState).toEqual(expectedPutGithubInstallation(testOrgInstallation))
6049
expect(result).toEqual([testOrgInstallation])
6150
})
Lines changed: 15 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test } from 'vitest'
1+
import { test } from 'vitest'
22
import { FakeAppState } from '../../../../../testSupport/fakes/fakeAppState'
33
import { FakeGithubInstallationClient } from '../../../../../testSupport/fakes/fakeGithubInstallationClient'
44
import {
@@ -12,6 +12,14 @@ import {
1212
import example_personal_repo_push from '../../../../../examples/github/personal-account/api/repoPush.json'
1313
import example_org_repo_push from '../../../../../examples/github/org/api/repoPush.json'
1414
import { crawlPushes } from '../../../../../../src/app/domain/github/crawler/crawlPushes'
15+
import {
16+
expectPut,
17+
expectPutsLength
18+
} from '../../../../../testSupport/fakes/dynamoDB/fakeDynamoDBInterfaceExpectations'
19+
import {
20+
expectedPutGithubPush,
21+
expectedPutLatestGithubPush
22+
} from '../../../../../testSupport/fakes/tableRecordExpectedWrites'
1523

1624
test('repo-crawler-for-personal-account-installation', async () => {
1725
// A
@@ -30,39 +38,9 @@ test('repo-crawler-for-personal-account-installation', async () => {
3038
await crawlPushes(appState, testPersonalInstallation, testPersonalTestRepo)
3139

3240
// A
33-
expect(appState.dynamoDB.puts.length).toEqual(2)
34-
expect(appState.dynamoDB.puts[0]).toEqual({
35-
ConditionExpression: 'attribute_not_exists(PK)',
36-
Item: {
37-
PK: 'ACCOUNT#162360409',
38-
SK: 'REPO#767679529#REF#refs/heads/main#PUSH#COMMIT#dfb5cb80ad3ce5a19a5020b4645696b2d6b4d94c',
39-
GSI1PK: 'ACCOUNT#162360409',
40-
GSI1SK: 'REPO#767679529#DATETIME#2024-03-05T18:01:12Z',
41-
_et: 'githubPush',
42-
_lastUpdated: '2024-02-02T19:00:00.000Z',
43-
...testPersonalTestRepoPush
44-
},
45-
TableName: 'fakeGithubRepoActivityTable'
46-
})
47-
expect(appState.dynamoDB.puts[1]).toEqual({
48-
ConditionExpression: 'attribute_not_exists(PK) OR #dateTime < :newDateTime',
49-
ExpressionAttributeNames: {
50-
'#dateTime': 'dateTime'
51-
},
52-
ExpressionAttributeValues: {
53-
':newDateTime': '2024-03-05T18:01:12Z'
54-
},
55-
Item: {
56-
PK: 'ACCOUNT#162360409',
57-
SK: 'REPO#767679529#REF#refs/heads/main',
58-
GSI1PK: 'ACCOUNT#162360409',
59-
GSI1SK: 'DATETIME#2024-03-05T18:01:12Z',
60-
_et: 'githubLatestPushPerRef',
61-
_lastUpdated: '2024-02-02T19:00:00.000Z',
62-
...testPersonalTestRepoPush
63-
},
64-
TableName: 'fakeGithubLatestPushesPerRefTable'
65-
})
41+
expectPutsLength(appState).toEqual(2)
42+
expectPut(appState, 0).toEqual(expectedPutGithubPush(testPersonalTestRepoPush))
43+
expectPut(appState, 1).toEqual(expectedPutLatestGithubPush(testPersonalTestRepoPush))
6644
})
6745

6846
test('repo-crawler-for-org-installation', async () => {
@@ -82,37 +60,7 @@ test('repo-crawler-for-org-installation', async () => {
8260
await crawlPushes(appState, testOrgInstallation, testOrgTestRepoOne)
8361

8462
// A
85-
expect(appState.dynamoDB.puts.length).toEqual(2)
86-
expect(appState.dynamoDB.puts[0]).toEqual({
87-
ConditionExpression: 'attribute_not_exists(PK)',
88-
Item: {
89-
PK: 'ACCOUNT#162483619',
90-
SK: 'REPO#768206479#REF#refs/heads/main#PUSH#COMMIT#8c3aa1cb0316ea23abeb2612457edb80868f53c8',
91-
GSI1PK: 'ACCOUNT#162483619',
92-
GSI1SK: 'REPO#768206479#DATETIME#2024-03-06T17:00:40Z',
93-
_et: 'githubPush',
94-
_lastUpdated: '2024-02-02T19:00:00.000Z',
95-
...testOrgTestRepoOnePush
96-
},
97-
TableName: 'fakeGithubRepoActivityTable'
98-
})
99-
expect(appState.dynamoDB.puts[1]).toEqual({
100-
ConditionExpression: 'attribute_not_exists(PK) OR #dateTime < :newDateTime',
101-
ExpressionAttributeNames: {
102-
'#dateTime': 'dateTime'
103-
},
104-
ExpressionAttributeValues: {
105-
':newDateTime': '2024-03-06T17:00:40Z'
106-
},
107-
Item: {
108-
PK: 'ACCOUNT#162483619',
109-
SK: 'REPO#768206479#REF#refs/heads/main',
110-
GSI1PK: 'ACCOUNT#162483619',
111-
GSI1SK: 'DATETIME#2024-03-06T17:00:40Z',
112-
_et: 'githubLatestPushPerRef',
113-
_lastUpdated: '2024-02-02T19:00:00.000Z',
114-
...testOrgTestRepoOnePush
115-
},
116-
TableName: 'fakeGithubLatestPushesPerRefTable'
117-
})
63+
expectPutsLength(appState).toEqual(2)
64+
expectPut(appState, 0).toEqual(expectedPutGithubPush(testOrgTestRepoOnePush))
65+
expectPut(appState, 1).toEqual(expectedPutLatestGithubPush(testOrgTestRepoOnePush))
11866
})
Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test } from 'vitest'
1+
import { test } from 'vitest'
22
import { FakeAppState } from '../../../../../testSupport/fakes/fakeAppState'
33
import { FakeGithubInstallationClient } from '../../../../../testSupport/fakes/fakeGithubInstallationClient'
44
import {
@@ -11,6 +11,11 @@ import {
1111
import example_personal_account_repo from '../../../../../examples/github/personal-account/api/repo.json'
1212
import example_org_repos from '../../../../../examples/github/org/api/repos.json'
1313
import { crawlRepositories } from '../../../../../../src/app/domain/github/crawler/crawlRepositories'
14+
import {
15+
expectBatchWrites,
16+
expectBatchWritesLength
17+
} from '../../../../../testSupport/fakes/dynamoDB/fakeDynamoDBInterfaceExpectations'
18+
import { expectedBatchWriteGithubRepositories } from '../../../../../testSupport/fakes/tableRecordExpectedWrites'
1419

1520
test('repository-crawler-for-personal-account-installation', async () => {
1621
// A
@@ -23,24 +28,8 @@ test('repository-crawler-for-personal-account-installation', async () => {
2328
await crawlRepositories(appState, testPersonalInstallation)
2429

2530
// A
26-
expect(appState.dynamoDB.batchWrites.length).toEqual(1)
27-
expect(appState.dynamoDB.batchWrites[0]).toEqual({
28-
RequestItems: {
29-
fakeGithubRepositoriesTable: [
30-
{
31-
PutRequest: {
32-
Item: {
33-
PK: 'OWNER#162360409',
34-
SK: 'REPO#767679529',
35-
_et: 'githubRepository',
36-
_lastUpdated: '2024-02-02T19:00:00.000Z',
37-
...testPersonalTestRepo
38-
}
39-
}
40-
}
41-
]
42-
}
43-
})
31+
expectBatchWritesLength(appState).toEqual(1)
32+
expectBatchWrites(appState, 0).toEqual(expectedBatchWriteGithubRepositories([testPersonalTestRepo]))
4433
})
4534

4635
test('repository-crawler-for-org-installation', async () => {
@@ -54,34 +43,8 @@ test('repository-crawler-for-org-installation', async () => {
5443
await crawlRepositories(appState, testOrgInstallation)
5544

5645
// A
57-
expect(appState.dynamoDB.batchWrites.length).toEqual(1)
58-
59-
expect(appState.dynamoDB.batchWrites[0]).toEqual({
60-
RequestItems: {
61-
fakeGithubRepositoriesTable: [
62-
{
63-
PutRequest: {
64-
Item: {
65-
PK: 'OWNER#162483619',
66-
SK: 'REPO#768206479',
67-
_et: 'githubRepository',
68-
_lastUpdated: '2024-02-02T19:00:00.000Z',
69-
...testOrgTestRepoOne
70-
}
71-
}
72-
},
73-
{
74-
PutRequest: {
75-
Item: {
76-
PK: 'OWNER#162483619',
77-
SK: 'REPO#768207426',
78-
_et: 'githubRepository',
79-
_lastUpdated: '2024-02-02T19:00:00.000Z',
80-
...testOrgTestRepoTwo
81-
}
82-
}
83-
}
84-
]
85-
}
86-
})
46+
expectBatchWritesLength(appState).toEqual(1)
47+
expectBatchWrites(appState, 0).toEqual(
48+
expectedBatchWriteGithubRepositories([testOrgTestRepoOne, testOrgTestRepoTwo])
49+
)
8750
})
Lines changed: 18 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test } from 'vitest'
1+
import { test } from 'vitest'
22
import { FakeAppState } from '../../../../../testSupport/fakes/fakeAppState'
33
import { FakeGithubInstallationClient } from '../../../../../testSupport/fakes/fakeGithubInstallationClient'
44
import {
@@ -13,6 +13,15 @@ import {
1313
import example_personal_workflow_run from '../../../../../examples/github/personal-account/api/workflowRunEvent.json'
1414
import example_org_workflow_run from '../../../../../examples/github/org/api/workflowRunEvent.json'
1515
import { crawlWorkflowRunEvents } from '../../../../../../src/app/domain/github/crawler/crawlRunEvents'
16+
import {
17+
expectPut,
18+
expectPutsLength
19+
} from '../../../../../testSupport/fakes/dynamoDB/fakeDynamoDBInterfaceExpectations'
20+
import {
21+
expectedPutGithubWorkflowRun,
22+
expectedPutGithubWorkflowRunEvent,
23+
expectedPutLatestGithubWorkflowRunEvent
24+
} from '../../../../../testSupport/fakes/tableRecordExpectedWrites'
1625

1726
test('repo-crawler-for-personal-account-installation', async () => {
1827
// A
@@ -32,58 +41,10 @@ test('repo-crawler-for-personal-account-installation', async () => {
3241
await crawlWorkflowRunEvents(appState, testPersonalInstallation, testPersonalTestRepo, 10)
3342

3443
// A
35-
expect(appState.dynamoDB.puts.length).toEqual(3)
36-
expect(appState.dynamoDB.puts[0]).toEqual({
37-
ConditionExpression: 'attribute_not_exists(PK)',
38-
Item: {
39-
PK: 'ACCOUNT#162360409',
40-
SK: 'REPO#767679529#WORKFLOW#88508779#WORKFLOW_RUN_EVENT#UPDATED_AT#2024-03-05T18:01:40Z#RUN#8160866530#STATUS#completed',
41-
GSI1PK: 'ACCOUNT#162360409',
42-
GSI1SK: 'REPO#767679529#DATETIME#2024-03-05T18:01:40Z',
43-
_et: 'githubWorkflowRunEvent',
44-
_lastUpdated: '2024-02-02T19:00:00.000Z',
45-
...testPersonalTestRepoWorkflowRun
46-
},
47-
TableName: 'fakeGithubRepoActivityTable'
48-
})
49-
expect(appState.dynamoDB.puts[1]).toEqual({
50-
ConditionExpression: 'attribute_not_exists(PK) OR #updatedAt < :newUpdatedAt',
51-
ExpressionAttributeNames: {
52-
'#updatedAt': 'updatedAt'
53-
},
54-
ExpressionAttributeValues: {
55-
':newUpdatedAt': '2024-03-05T18:01:40Z'
56-
},
57-
Item: {
58-
PK: 'ACCOUNT#162360409',
59-
SK: 'REPO#767679529#WORKFLOW#88508779#WORKFLOW_RUN#RUN#8160866530',
60-
GSI1PK: 'ACCOUNT#162360409',
61-
GSI1SK: 'REPO#767679529#DATETIME#2024-03-05T18:01:40Z',
62-
_et: 'githubWorkflowRun',
63-
_lastUpdated: '2024-02-02T19:00:00.000Z',
64-
...testPersonalTestRepoWorkflowRun
65-
},
66-
TableName: 'fakeGithubRepoActivityTable'
67-
})
68-
expect(appState.dynamoDB.puts[2]).toEqual({
69-
ConditionExpression: 'attribute_not_exists(PK) OR #updatedAt < :newUpdatedAt',
70-
ExpressionAttributeNames: {
71-
'#updatedAt': 'updatedAt'
72-
},
73-
ExpressionAttributeValues: {
74-
':newUpdatedAt': '2024-03-05T18:01:40Z'
75-
},
76-
Item: {
77-
PK: 'ACCOUNT#162360409',
78-
SK: 'REPO#767679529#WORKFLOW#88508779',
79-
GSI1PK: 'ACCOUNT#162360409',
80-
GSI1SK: 'DATETIME#2024-03-05T18:01:40Z',
81-
_et: 'githubLatestWorkflowRunEvent',
82-
_lastUpdated: '2024-02-02T19:00:00.000Z',
83-
...testPersonalTestRepoWorkflowRun
84-
},
85-
TableName: 'fakeGithubLatestWorkflowRunsTable'
86-
})
44+
expectPutsLength(appState).toEqual(3)
45+
expectPut(appState, 0).toEqual(expectedPutGithubWorkflowRunEvent(testPersonalTestRepoWorkflowRun))
46+
expectPut(appState, 1).toEqual(expectedPutGithubWorkflowRun(testPersonalTestRepoWorkflowRun))
47+
expectPut(appState, 2).toEqual(expectedPutLatestGithubWorkflowRunEvent(testPersonalTestRepoWorkflowRun))
8748
})
8849

8950
test('repo-crawler-for-org-installation', async () => {
@@ -104,56 +65,8 @@ test('repo-crawler-for-org-installation', async () => {
10465
await crawlWorkflowRunEvents(appState, testOrgInstallation, testOrgTestRepoOne, 10)
10566

10667
// A
107-
expect(appState.dynamoDB.puts.length).toEqual(3)
108-
expect(appState.dynamoDB.puts[0]).toEqual({
109-
ConditionExpression: 'attribute_not_exists(PK)',
110-
Item: {
111-
PK: 'ACCOUNT#162483619',
112-
SK: 'REPO#768206479#WORKFLOW#88647110#WORKFLOW_RUN_EVENT#UPDATED_AT#2024-03-06T17:02:54Z#RUN#8175883775#STATUS#completed',
113-
GSI1PK: 'ACCOUNT#162483619',
114-
GSI1SK: 'REPO#768206479#DATETIME#2024-03-06T17:02:54Z',
115-
_et: 'githubWorkflowRunEvent',
116-
_lastUpdated: '2024-02-02T19:00:00.000Z',
117-
...testOrgTestRepoOneWorkflowRunOne
118-
},
119-
TableName: 'fakeGithubRepoActivityTable'
120-
})
121-
expect(appState.dynamoDB.puts[1]).toEqual({
122-
ConditionExpression: 'attribute_not_exists(PK) OR #updatedAt < :newUpdatedAt',
123-
ExpressionAttributeNames: {
124-
'#updatedAt': 'updatedAt'
125-
},
126-
ExpressionAttributeValues: {
127-
':newUpdatedAt': '2024-03-06T17:02:54Z'
128-
},
129-
Item: {
130-
PK: 'ACCOUNT#162483619',
131-
SK: 'REPO#768206479#WORKFLOW#88647110#WORKFLOW_RUN#RUN#8175883775',
132-
GSI1PK: 'ACCOUNT#162483619',
133-
GSI1SK: 'REPO#768206479#DATETIME#2024-03-06T17:02:54Z',
134-
_et: 'githubWorkflowRun',
135-
_lastUpdated: '2024-02-02T19:00:00.000Z',
136-
...testOrgTestRepoOneWorkflowRunOne
137-
},
138-
TableName: 'fakeGithubRepoActivityTable'
139-
})
140-
expect(appState.dynamoDB.puts[2]).toEqual({
141-
ConditionExpression: 'attribute_not_exists(PK) OR #updatedAt < :newUpdatedAt',
142-
ExpressionAttributeNames: {
143-
'#updatedAt': 'updatedAt'
144-
},
145-
ExpressionAttributeValues: {
146-
':newUpdatedAt': '2024-03-06T17:02:54Z'
147-
},
148-
Item: {
149-
PK: 'ACCOUNT#162483619',
150-
SK: 'REPO#768206479#WORKFLOW#88647110',
151-
GSI1PK: 'ACCOUNT#162483619',
152-
GSI1SK: 'DATETIME#2024-03-06T17:02:54Z',
153-
_et: 'githubLatestWorkflowRunEvent',
154-
_lastUpdated: '2024-02-02T19:00:00.000Z',
155-
...testOrgTestRepoOneWorkflowRunOne
156-
},
157-
TableName: 'fakeGithubLatestWorkflowRunsTable'
158-
})
68+
expectPutsLength(appState).toEqual(3)
69+
expectPut(appState, 0).toEqual(expectedPutGithubWorkflowRunEvent(testOrgTestRepoOneWorkflowRunOne))
70+
expectPut(appState, 1).toEqual(expectedPutGithubWorkflowRun(testOrgTestRepoOneWorkflowRunOne))
71+
expectPut(appState, 2).toEqual(expectedPutLatestGithubWorkflowRunEvent(testOrgTestRepoOneWorkflowRunOne))
15972
})

test/local/functional/domain/github/crawler/crawlUsers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import example_personal_account_user from '../../../../../examples/github/personal-account/api/user.json'
1515
import example_org_users from '../../../../../examples/github/org/api/users.json'
1616
import { crawlUsers } from '../../../../../../src/app/domain/github/crawler/crawlUsers'
17-
import { stubQueryAccountMembershipsByAccount } from '../../../../../testSupport/fakes/fakeTableRecords'
17+
import { stubQueryAccountMembershipsByAccount } from '../../../../../testSupport/fakes/tableRecordReadStubs'
1818

1919
test('user-crawler-for-personal-account-installation', async () => {
2020
// A

0 commit comments

Comments
 (0)