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
30 lines
842 B
TypeScript
30 lines
842 B
TypeScript
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
|
import { IAuthModuleService } from "@medusajs/types"
|
|
import jwt from "jsonwebtoken"
|
|
import { getContainer } from "../../environment-helpers/use-container"
|
|
import adminSeeder from "../../helpers/admin-seeder"
|
|
|
|
export const createAdminUser = async (
|
|
dbConnection,
|
|
adminHeaders,
|
|
container?
|
|
) => {
|
|
await adminSeeder(dbConnection)
|
|
const appContainer = container ?? getContainer()!
|
|
|
|
const authModule: IAuthModuleService = appContainer.resolve(
|
|
ModuleRegistrationName.AUTH
|
|
)
|
|
const authUser = await authModule.create({
|
|
provider: "emailpass",
|
|
entity_id: "admin@medusa.js",
|
|
scope: "admin",
|
|
app_metadata: {
|
|
user_id: "admin_user",
|
|
},
|
|
})
|
|
|
|
const token = jwt.sign(authUser, "test")
|
|
adminHeaders.headers["authorization"] = `Bearer ${token}`
|
|
}
|