-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
602 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,6 +337,101 @@ func TestMemberStoreGetWhenErrors(t *testing.T) { | |
} | ||
|
||
func TestMemberStoreCreate(t *testing.T) { | ||
ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "session-id", Email: "[email protected]"}) | ||
expectedMember := &actor.Member{ | ||
PK: "ORGANISATION#a-uuid", | ||
SK: "MEMBER#session-id", | ||
CreatedAt: testNow, | ||
UpdatedAt: testNow, | ||
ID: "a-uuid", | ||
OrganisationID: "a-uuid", | ||
Email: "[email protected]", | ||
FirstNames: "a", | ||
LastName: "b", | ||
Permission: actor.PermissionAdmin, | ||
Status: actor.StatusActive, | ||
LastLoggedInAt: testNow, | ||
} | ||
|
||
dynamoClient := newMockDynamoClient(t) | ||
dynamoClient.EXPECT(). | ||
Create(ctx, expectedMember). | ||
Return(nil). | ||
Once() | ||
dynamoClient.EXPECT(). | ||
Create(ctx, &organisationLink{ | ||
PK: "ORGANISATION#a-uuid", | ||
SK: "MEMBERID#a-uuid", | ||
MemberSK: "MEMBER#session-id", | ||
}). | ||
Return(nil). | ||
Once() | ||
|
||
memberStore := &memberStore{dynamoClient: dynamoClient, now: testNowFn, uuidString: func() string { return "a-uuid" }} | ||
|
||
member, err := memberStore.Create(ctx, "a", "b") | ||
assert.Nil(t, err) | ||
assert.Equal(t, expectedMember, member) | ||
} | ||
|
||
func TestMemberStoreCreateWhenSessionMissing(t *testing.T) { | ||
testCases := map[string]context.Context{ | ||
"missing session": context.Background(), | ||
"missing session ID": page.ContextWithSessionData(context.Background(), &page.SessionData{}), | ||
} | ||
|
||
for name, ctx := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
memberStore := &memberStore{dynamoClient: nil, now: testNowFn, uuidString: func() string { return "a-uuid" }} | ||
|
||
_, err := memberStore.Create(ctx, "a", "b") | ||
assert.Error(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func TestMemberStoreCreateWhenDynamoErrors(t *testing.T) { | ||
ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "session-id", Email: "a"}) | ||
|
||
testcases := map[string]struct { | ||
dynamoClientSetup func(*mockDynamoClient) | ||
}{ | ||
"member": { | ||
dynamoClientSetup: func(dynamoClient *mockDynamoClient) { | ||
dynamoClient.EXPECT(). | ||
Create(ctx, mock.Anything). | ||
Return(expectedError). | ||
Once() | ||
}, | ||
}, | ||
"link": { | ||
dynamoClientSetup: func(dynamoClient *mockDynamoClient) { | ||
dynamoClient.EXPECT(). | ||
Create(ctx, mock.Anything). | ||
Return(nil). | ||
Once() | ||
dynamoClient.EXPECT(). | ||
Create(ctx, mock.Anything). | ||
Return(expectedError). | ||
Once() | ||
}, | ||
}, | ||
} | ||
|
||
for name, tc := range testcases { | ||
t.Run(name, func(t *testing.T) { | ||
dynamoClient := newMockDynamoClient(t) | ||
tc.dynamoClientSetup(dynamoClient) | ||
|
||
memberStore := &memberStore{dynamoClient: dynamoClient, now: testNowFn, uuidString: func() string { return "a-uuid" }} | ||
|
||
_, err := memberStore.Create(ctx, "a", "b") | ||
assert.ErrorIs(t, err, expectedError) | ||
}) | ||
} | ||
} | ||
|
||
func TestMemberStoreCreateFromInvite(t *testing.T) { | ||
ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "session-id"}) | ||
|
||
invite := &actor.MemberInvite{ | ||
|
@@ -357,6 +452,7 @@ func TestMemberStoreCreate(t *testing.T) { | |
CreatedAt: testNow, | ||
UpdatedAt: testNow, | ||
ID: "a-uuid", | ||
OrganisationID: "org-id", | ||
Email: invite.Email, | ||
FirstNames: invite.FirstNames, | ||
LastName: invite.LastName, | ||
|
@@ -380,11 +476,11 @@ func TestMemberStoreCreate(t *testing.T) { | |
|
||
memberStore := &memberStore{dynamoClient: dynamoClient, now: testNowFn, uuidString: func() string { return "a-uuid" }} | ||
|
||
err := memberStore.Create(ctx, invite) | ||
err := memberStore.CreateFromInvite(ctx, invite) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestMemberStoreCreateWhenSessionMissing(t *testing.T) { | ||
func TestMemberStoreCreateFromInviteWhenSessionMissing(t *testing.T) { | ||
testCases := map[string]context.Context{ | ||
"missing session": context.Background(), | ||
"missing session ID": page.ContextWithSessionData(context.Background(), &page.SessionData{}), | ||
|
@@ -394,13 +490,13 @@ func TestMemberStoreCreateWhenSessionMissing(t *testing.T) { | |
t.Run(name, func(t *testing.T) { | ||
memberStore := &memberStore{dynamoClient: nil, now: testNowFn, uuidString: func() string { return "a-uuid" }} | ||
|
||
err := memberStore.Create(ctx, &actor.MemberInvite{}) | ||
err := memberStore.CreateFromInvite(ctx, &actor.MemberInvite{}) | ||
assert.Error(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func TestMemberStoreCreateWhenDynamoErrors(t *testing.T) { | ||
func TestMemberStoreCreateFromInviteWhenDynamoErrors(t *testing.T) { | ||
testcases := map[string]struct { | ||
createMemberError error | ||
deleteOneError error | ||
|
@@ -441,11 +537,10 @@ func TestMemberStoreCreateWhenDynamoErrors(t *testing.T) { | |
} | ||
memberStore := &memberStore{dynamoClient: dynamoClient, now: testNowFn, uuidString: func() string { return "a-uuid" }} | ||
|
||
err := memberStore.Create(ctx, &actor.MemberInvite{}) | ||
err := memberStore.CreateFromInvite(ctx, &actor.MemberInvite{}) | ||
assert.Error(t, err) | ||
}) | ||
} | ||
|
||
} | ||
|
||
func TestMemberStoreGetByID(t *testing.T) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.