Few things to keep in mind: 1. You need to set MEDUSA_FF_MEDUSA_V2 to true before running the tests to run with the v2 API 2. You can use the `breaking` function to differentiate between v1 and v2 differences. This can help us identify what was breaking pretty quickly afterwards 3. You will need to run specific tests for now instead of all if you want to target v2. I think that's fine though, as we don't really need these to run on every PR until we have feature parity (and by then, all tests would be both v1 and v2 compatible) **note: Adrien** - add a new way to load modules only to run their loaders comparable to the way to run the migrations only - improve tests runner to cleanup the data properly as well as re running all loaders and core defaults Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
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",
|
|
})
|
|
)
|
|
})
|
|
})
|
|
},
|
|
})
|