Skip to content

Commit 7fd4a18

Browse files
committed
Functional test refactoring
Func tests are starting to get verbose, so working on some cleanup Some of this work will be able to be pushed up to dynamodb-entity-store
1 parent e7bc939 commit 7fd4a18

18 files changed

+547
-568
lines changed

test/examples/cicada/githubDomainObjects.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ export const testMikeRobertsUserMembershipOfOrg: GithubAccountMembership = {
6262
userId: 49635
6363
}
6464

65+
export const accountMemberships: Record<number, GithubAccountMembership> = {
66+
162360409: testTestUserMembershipOfOrg,
67+
49635: testMikeRobertsUserMembershipOfOrg
68+
}
69+
6570
export const testPersonalTestRepo: GithubRepository = {
6671
archived: false,
6772
createdAt: '2024-03-05T17:56:33Z',

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

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import {
66
testOrgTestRepoOne,
77
testOrgTestRepoTwo,
88
testPersonalInstallation,
9-
testPersonalTestRepo,
10-
testTestUserMembershipOfOrg
9+
testPersonalTestRepo
1110
} from '../../../../../examples/cicada/githubDomainObjects'
1211
import example_personal_account_repo from '../../../../../examples/github/personal-account/api/repo.json'
1312
import example_org_repos from '../../../../../examples/github/org/api/repos.json'
@@ -50,30 +49,6 @@ test('repository-crawler-for-org-installation', async () => {
5049
const githubInstallationClient = new FakeGithubInstallationClient()
5150
appState.githubClient.fakeClientsForInstallation.addResponse(48133709, githubInstallationClient)
5251
githubInstallationClient.stubOrganizationRepositories.addResponse('cicada-test-org', example_org_repos)
53-
appState.dynamoDB.stubAllPagesQueries.addResponse(
54-
{
55-
TableName: 'fakeGithubAccountMemberships',
56-
KeyConditionExpression: 'PK = :pk',
57-
ExpressionAttributeValues: { ':pk': 'ACCOUNT#162483619' }
58-
},
59-
[
60-
{
61-
$metadata: {},
62-
Items: [
63-
{
64-
_et: 'githubAccountMembership',
65-
...testTestUserMembershipOfOrg
66-
},
67-
// Old membership that will be deleted
68-
{
69-
_et: 'githubAccountMembership',
70-
...testTestUserMembershipOfOrg,
71-
userId: 9786
72-
}
73-
]
74-
}
75-
]
76-
)
7752

7853
// A
7954
await crawlRepositories(appState, testOrgInstallation)

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

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +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'
1718

1819
test('user-crawler-for-personal-account-installation', async () => {
1920
// A
@@ -71,30 +72,11 @@ test('user-crawler-for-org-installation', async () => {
7172
appState.githubClient.fakeClientsForInstallation.addResponse(48133709, githubInstallationClient)
7273
githubInstallationClient.stubOrganizationMembers.addResponse('cicada-test-org', example_org_users)
7374

74-
appState.dynamoDB.stubAllPagesQueries.addResponse(
75-
{
76-
TableName: 'fakeGithubAccountMemberships',
77-
KeyConditionExpression: 'PK = :pk',
78-
ExpressionAttributeValues: { ':pk': 'ACCOUNT#162483619' }
79-
},
80-
[
81-
{
82-
$metadata: {},
83-
Items: [
84-
{
85-
_et: 'githubAccountMembership',
86-
...testTestUserMembershipOfOrg
87-
},
88-
// Old membership that will be deleted
89-
{
90-
_et: 'githubAccountMembership',
91-
...testTestUserMembershipOfOrg,
92-
userId: 9786
93-
}
94-
]
95-
}
96-
]
97-
)
75+
stubQueryAccountMembershipsByAccount(appState, [
76+
testTestUserMembershipOfOrg,
77+
// Old membership that will be deleted
78+
{ ...testTestUserMembershipOfOrg, userId: 9786 }
79+
])
9880

9981
// A
10082
await crawlUsers(appState, testOrgInstallation)

test/local/functional/domain/github/githubUserAuth/githubWebAuthHandler.test.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect, test } from 'vitest'
22
import { createStubApiGatewayProxyEvent } from '../../../../../testSupport/fakes/awsStubs'
33
import { FakeAppState } from '../../../../../testSupport/fakes/fakeAppState'
4-
import { GITHUB_USER } from '../../../../../../src/app/domain/entityStore/entityTypes'
54
import { handleGitHubWebAuthRequest } from '../../../../../../src/app/domain/github/githubUserAuth/githubWebAuthHandler'
5+
import { stubGetUser } from '../../../../../testSupport/fakes/fakeTableRecords'
66

77
test('login', async () => {
88
const response = await handleGitHubWebAuthRequest(
@@ -34,32 +34,13 @@ test('oauthCallback', async () => {
3434
})
3535
appState.githubClient.stubGithubUsers.addResponse('validUserToken', {
3636
login: 'testLogin',
37-
id: 123456,
37+
id: 162360409,
3838
avatar_url: '',
3939
html_url: '',
4040
type: '',
4141
url: ''
4242
})
43-
appState.dynamoDB.stubGets.addResponse(
44-
{
45-
TableName: 'fakeGithubUsersTable',
46-
Key: {
47-
PK: 'USER#123456'
48-
}
49-
},
50-
{
51-
Item: {
52-
PK: 'USER#123456',
53-
_et: GITHUB_USER,
54-
login: 'fakeUserLogin',
55-
id: 123456,
56-
avatarUrl: '',
57-
htmlUrl: '',
58-
url: ''
59-
},
60-
$metadata: {}
61-
}
62-
)
43+
stubGetUser(appState)
6344

6445
// Act
6546
const response = await handleGitHubWebAuthRequest(

test/local/functional/domain/github/webPush/webPushEvents.test.ts

Lines changed: 19 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,31 @@
11
import { expect, test } from 'vitest'
22
import { FakeAppState } from '../../../../../testSupport/fakes/fakeAppState'
3-
import {
4-
testMikeRobertsUserMembershipOfOrg,
5-
testOrgTestRepoOneWorkflowRunThree,
6-
testTestUserMembershipOfOrg
7-
} from '../../../../../examples/cicada/githubDomainObjects'
8-
import {
9-
GITHUB_ACCOUNT_MEMBERSHIP,
10-
GITHUB_LATEST_WORKFLOW_RUN_EVENT,
11-
WEB_PUSH_SUBSCRIPTION
12-
} from '../../../../../../src/app/domain/entityStore/entityTypes'
3+
import { testOrgTestRepoOneWorkflowRunThree } from '../../../../../examples/cicada/githubDomainObjects'
134
import { processEventBridgeWebPushEvent } from '../../../../../../src/app/domain/webPush/webPushEventBridgeEventProcessor'
145
import {
156
testMikeRobertsPushSubscriptionThree,
16-
testMikeRobertsPushSubscriptionTwo,
17-
testTestUserPushSubscription
7+
testMikeRobertsPushSubscriptionTwo
188
} from '../../../../../examples/cicada/webPushDomainObjects'
199
import { EVENTBRIDGE_DETAIL_TYPES } from '../../../../../../src/multipleContexts/eventBridge'
10+
import {
11+
stubQueryAccountMembershipsByAccount,
12+
stubQueryAccountMembershipsByUser,
13+
stubQueryLatestWorkflowRuns,
14+
stubQueryWebPushSubscription
15+
} from '../../../../../testSupport/fakes/fakeTableRecords'
2016

2117
test('newWorkflowRunEvent', async () => {
2218
const appState = new FakeAppState()
23-
appState.dynamoDB.stubAllPagesQueries.addResponse(
24-
{
25-
TableName: 'fakeGithubAccountMemberships',
26-
KeyConditionExpression: 'PK = :pk',
27-
ExpressionAttributeValues: { ':pk': 'ACCOUNT#162483619' }
28-
},
29-
[
30-
{
31-
$metadata: {},
32-
Items: [
33-
{ ...testTestUserMembershipOfOrg, _et: GITHUB_ACCOUNT_MEMBERSHIP },
34-
{ ...testMikeRobertsUserMembershipOfOrg, _et: GITHUB_ACCOUNT_MEMBERSHIP }
35-
]
36-
}
37-
]
38-
)
39-
appState.dynamoDB.stubAllPagesQueries.addResponse(
40-
{
41-
TableName: 'fakeGithubAccountMemberships',
42-
KeyConditionExpression: 'GSI1PK = :pk',
43-
IndexName: 'GSI1',
44-
ExpressionAttributeValues: { ':pk': 'USER#162360409' }
45-
},
46-
[
47-
{
48-
$metadata: {},
49-
Items: [{ ...testTestUserMembershipOfOrg, _et: GITHUB_ACCOUNT_MEMBERSHIP }]
50-
}
51-
]
52-
)
53-
appState.dynamoDB.stubAllPagesQueries.addResponse(
54-
{
55-
TableName: 'fakeGithubAccountMemberships',
56-
KeyConditionExpression: 'GSI1PK = :pk',
57-
IndexName: 'GSI1',
58-
ExpressionAttributeValues: { ':pk': 'USER#49635' }
59-
},
60-
[
61-
{
62-
$metadata: {},
63-
Items: [{ ...testMikeRobertsUserMembershipOfOrg, _et: GITHUB_ACCOUNT_MEMBERSHIP }]
64-
}
65-
]
66-
)
19+
stubQueryAccountMembershipsByAccount(appState)
6720

68-
appState.dynamoDB.stubAllPagesQueries.addResponse(
69-
{
70-
TableName: 'fakeGithubLatestWorkflowRunsTable',
71-
KeyConditionExpression: 'GSI1PK = :pk',
72-
IndexName: 'GSI1',
73-
ExpressionAttributeValues: { ':pk': 'ACCOUNT#162483619' },
74-
ScanIndexForward: false
75-
},
76-
[
77-
{
78-
$metadata: {},
79-
Items: [{ ...testOrgTestRepoOneWorkflowRunThree, _et: GITHUB_LATEST_WORKFLOW_RUN_EVENT }]
80-
}
81-
]
82-
)
83-
84-
appState.dynamoDB.stubAllPagesQueries.addResponse(
85-
{
86-
TableName: 'fakeWebPushSubscriptions',
87-
KeyConditionExpression: 'PK = :pk',
88-
ExpressionAttributeValues: { ':pk': 'USER#162360409' }
89-
},
90-
[
91-
{
92-
$metadata: {},
93-
Items: [
94-
{
95-
_et: WEB_PUSH_SUBSCRIPTION,
96-
...testTestUserPushSubscription
97-
}
98-
]
99-
}
100-
]
101-
)
102-
appState.dynamoDB.stubAllPagesQueries.addResponse(
103-
{
104-
TableName: 'fakeWebPushSubscriptions',
105-
KeyConditionExpression: 'PK = :pk',
106-
ExpressionAttributeValues: { ':pk': 'USER#49635' }
107-
},
108-
[
109-
{
110-
$metadata: {},
111-
Items: [
112-
{
113-
_et: WEB_PUSH_SUBSCRIPTION,
114-
...testMikeRobertsPushSubscriptionTwo
115-
},
116-
{
117-
_et: WEB_PUSH_SUBSCRIPTION,
118-
...testMikeRobertsPushSubscriptionThree
119-
}
120-
]
121-
}
122-
]
123-
)
21+
stubQueryAccountMembershipsByUser(appState)
22+
stubQueryAccountMembershipsByUser(appState, 49635)
23+
stubQueryLatestWorkflowRuns(appState)
24+
stubQueryWebPushSubscription(appState)
25+
stubQueryWebPushSubscription(appState, {
26+
userId: 49635,
27+
subscriptions: [testMikeRobertsPushSubscriptionTwo, testMikeRobertsPushSubscriptionThree]
28+
})
12429

12530
await processEventBridgeWebPushEvent(appState, {
12631
version: '0',
@@ -191,38 +96,9 @@ test('newWorkflowRunEvent', async () => {
19196

19297
test('newPushTest', async () => {
19398
const appState = new FakeAppState()
194-
appState.dynamoDB.stubAllPagesQueries.addResponse(
195-
{
196-
TableName: 'fakeGithubAccountMemberships',
197-
KeyConditionExpression: 'PK = :pk',
198-
ExpressionAttributeValues: { ':pk': 'ACCOUNT#162483619' }
199-
},
200-
[
201-
{
202-
$metadata: {},
203-
Items: [{ ...testTestUserMembershipOfOrg, _et: GITHUB_ACCOUNT_MEMBERSHIP }]
204-
}
205-
]
206-
)
20799

208-
appState.dynamoDB.stubAllPagesQueries.addResponse(
209-
{
210-
TableName: 'fakeWebPushSubscriptions',
211-
KeyConditionExpression: 'PK = :pk',
212-
ExpressionAttributeValues: { ':pk': 'USER#162360409' }
213-
},
214-
[
215-
{
216-
$metadata: {},
217-
Items: [
218-
{
219-
_et: WEB_PUSH_SUBSCRIPTION,
220-
...testTestUserPushSubscription
221-
}
222-
]
223-
}
224-
]
225-
)
100+
stubQueryAccountMembershipsByUser(appState)
101+
stubQueryWebPushSubscription(appState)
226102

227103
await processEventBridgeWebPushEvent(appState, {
228104
version: '0',

0 commit comments

Comments
 (0)