new wrapper for medusa integration tests. for now it is only applied to the modules directory, but it could be used in the api integration tests or any other integrations that requires a db and a server up and running. It is not perfect, but I wanted to have something working and centralised before improving it, also avoiding too many conflicts with other prs
92 lines
2.6 KiB
TypeScript
92 lines
2.6 KiB
TypeScript
import { IUserModuleService } from "@medusajs/types"
|
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
|
import { createAdminUser } from "../../helpers/create-admin-user"
|
|
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
|
|
|
jest.setTimeout(50000)
|
|
|
|
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
|
const adminHeaders = {
|
|
headers: { "x-medusa-access-token": "test_token" },
|
|
}
|
|
|
|
medusaIntegrationTestRunner({
|
|
env,
|
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
|
describe("GET /admin/invites/:id", () => {
|
|
let appContainer
|
|
let userModuleService: IUserModuleService
|
|
|
|
beforeAll(async () => {
|
|
appContainer = getContainer()
|
|
userModuleService = appContainer.resolve(ModuleRegistrationName.USER)
|
|
})
|
|
|
|
beforeEach(async () => {
|
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
|
})
|
|
|
|
it("should fail to accept an invite with an invalid invite token", async () => {
|
|
const authResponse = await api.post(`/auth/admin/emailpass`, {
|
|
email: "potential_member@test.com",
|
|
password: "supersecret",
|
|
})
|
|
|
|
expect(authResponse.status).toEqual(200)
|
|
const token = authResponse.data.token
|
|
|
|
const acceptResponse = await api
|
|
.post(
|
|
`/admin/invites/accept?token=${"non-existing-token"}`,
|
|
{
|
|
first_name: "John",
|
|
},
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
}
|
|
)
|
|
.catch((e) => e)
|
|
|
|
expect(acceptResponse.response.status).toEqual(401)
|
|
expect(acceptResponse.response.data.message).toEqual("Unauthorized")
|
|
})
|
|
|
|
it("should accept an invite", async () => {
|
|
const invite = await userModuleService.createInvites({
|
|
email: "potential_member@test.com",
|
|
})
|
|
|
|
const authResponse = await api.post(`/auth/admin/emailpass`, {
|
|
email: "potential_member@test.com",
|
|
password: "supersecret",
|
|
})
|
|
|
|
expect(authResponse.status).toEqual(200)
|
|
const token = authResponse.data.token
|
|
|
|
const acceptResponse = await api.post(
|
|
`/admin/invites/accept?token=${invite.token}`,
|
|
{
|
|
first_name: "John",
|
|
},
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
},
|
|
}
|
|
)
|
|
|
|
expect(acceptResponse.status).toEqual(200)
|
|
expect(acceptResponse.data.user).toEqual(
|
|
expect.objectContaining({
|
|
email: "potential_member@test.com",
|
|
first_name: "John",
|
|
})
|
|
)
|
|
})
|
|
})
|
|
},
|
|
})
|