feat: Separate registration from authentication in auth domain (#8683)

* wip

* feat: Introduce register

* fix: user command

* fix: Invite HTTP tests

* fix: Auth tests

* fix: Invite modules tests
This commit is contained in:
Oli Juhl
2024-08-27 13:44:52 +02:00
committed by GitHub
parent c6eba80af6
commit c11ef01c15
21 changed files with 459 additions and 152 deletions
@@ -136,7 +136,7 @@ describe("Email password auth provider", () => {
}),
}
const resp = await emailpassService.authenticate(
const resp = await emailpassService.register(
{ body: { email: "test@admin.com", password: "test" } },
authServiceSpies
)
@@ -151,4 +151,52 @@ describe("Email password auth provider", () => {
})
)
})
it("throw if auth identity with email already exists", async () => {
const authServiceSpies = {
retrieve: jest.fn().mockImplementation(() => {
return { success: true }
}),
create: jest.fn().mockImplementation(() => {
return {
provider_identities: [
{
entity_id: "test@admin.com",
provider: "emailpass",
provider_metadata: {
password: "somehash",
},
},
],
}
}),
}
const resp = await emailpassService.register(
{ body: { email: "test@admin.com", password: "test" } },
authServiceSpies
)
expect(authServiceSpies.retrieve).toHaveBeenCalled()
expect(resp.error).toEqual("Identity with email already exists")
})
it("throws if auth identity with email doesn't exist", async () => {
const authServiceSpies = {
retrieve: jest.fn().mockImplementation(() => {
throw new MedusaError(MedusaError.Types.NOT_FOUND, "Not found")
}),
create: jest.fn().mockImplementation(() => {}),
}
const resp = await emailpassService.authenticate(
{ body: { email: "test@admin.com", password: "test" } },
authServiceSpies
)
expect(authServiceSpies.retrieve).toHaveBeenCalled()
expect(resp.error).toEqual("Invalid email or password")
})
})