diff --git a/integration-tests/aws-sdk/adminDeleteUser.test.ts b/integration-tests/aws-sdk/adminDeleteUser.test.ts index 71cc85bc..bb6aa4ce 100644 --- a/integration-tests/aws-sdk/adminDeleteUser.test.ts +++ b/integration-tests/aws-sdk/adminDeleteUser.test.ts @@ -60,6 +60,57 @@ describe( .promise() ).rejects.toEqual(new UserNotFoundError("User does not exist")); }); + + it("deletes a user with an email address as a username", async () => { + const client = Cognito(); + + // create the user + const createUserResult = await client + .adminCreateUser({ + UserAttributes: [ + { Name: "email", Value: "example@example.com" }, + { Name: "phone_number", Value: "0400000000" }, + ], + Username: "example@example.com", + UserPoolId: "test", + }) + .promise(); + + // verify they exist + const beforeUserResult = await client + .adminGetUser({ + Username: "example@example.com", + UserPoolId: "test", + }) + .promise(); + + expect(beforeUserResult).toEqual({ + Enabled: true, + UserAttributes: createUserResult.User?.Attributes, + UserCreateDate: createUserResult.User?.UserCreateDate, + UserLastModifiedDate: createUserResult.User?.UserLastModifiedDate, + Username: createUserResult.User?.Username, + UserStatus: createUserResult.User?.UserStatus, + }); + + // delete the user + await client + .adminDeleteUser({ + Username: "example@example.com", + UserPoolId: "test", + }) + .promise(); + + // verify they don't exist anymore + await expect( + client + .adminGetUser({ + Username: "example@example.com", + UserPoolId: "test", + }) + .promise() + ).rejects.toEqual(new UserNotFoundError("User does not exist")); + }); }, { clock, diff --git a/src/services/dataStore/stormDb.ts b/src/services/dataStore/stormDb.ts index ad65bbf9..def6e0d2 100644 --- a/src/services/dataStore/stormDb.ts +++ b/src/services/dataStore/stormDb.ts @@ -16,7 +16,7 @@ export class StormDBDataStore implements DataStore { async delete(ctx: Context, key: string | string[]) { ctx.logger.debug({ key }, "DataStore.delete"); (key instanceof Array ? key : [key]) - .reduce((acc, k) => acc.get(k), this.db) + .reduce((acc, k) => acc.get([k]), this.db) .delete(false); ctx.logger.debug({ store: this.db.value() }, "DataStore.save");