Move few test suites from api to http folder (#7558)

* chore: Move api key tests to http folder

* chore: Move some of the product category tests to http

* chore: Move collection tests to http

* chore: Remove unused database test
This commit is contained in:
Stevche Radevski
2024-05-31 16:12:04 +02:00
committed by GitHub
parent e66cf9112d
commit 294ec36cc3
4 changed files with 53 additions and 111 deletions

View File

@@ -1,56 +0,0 @@
const path = require("path")
const setupServer = require("../../../environment-helpers/setup-server")
const { initDb, useDb } = require("../../../environment-helpers/use-db")
jest.setTimeout(30000)
describe("Database options", () => {
let medusaProcess
let dbConnection
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({
cwd,
databaseExtra: { idle_in_transaction_session_timeout: 1000 },
})
medusaProcess = await setupServer({ cwd })
})
afterAll(async () => {
const db = useDb()
await db.shutdown()
medusaProcess.kill()
})
describe("idle_in_transaction_session_timeout", () => {
it("Resolves successfully", async () => {
expect.assertions(1)
let queryRunner
try {
queryRunner = dbConnection.createQueryRunner()
await queryRunner.connect()
await queryRunner.startTransaction()
await queryRunner.query(`select * from product`)
// Idle time is 1000 ms so this should timeout
await new Promise((resolve) =>
setTimeout(() => resolve(undefined), 2000)
)
// This query should fail with a QueryRunnerAlreadyReleasedError
await queryRunner.commitTransaction()
} catch (error) {
// Query runner will be released in case idle_in_transaction_session_timeout kicks in
expect(error?.type || error.name).toEqual(
"QueryRunnerAlreadyReleasedError"
)
}
})
})
})

View File

@@ -1,26 +1,18 @@
import { ApiKeyType, ContainerRegistrationKeys } from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { createAdminUser } from "../../../helpers/create-admin-user"
import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}
medusaIntegrationTestRunner({
env,
env: {},
testSuite: ({ dbConnection, getContainer, api }) => {
describe("API Keys - Admin", () => {
let container
beforeAll(async () => {
container = getContainer()
})
beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders, container)
await createAdminUser(dbConnection, adminHeaders, getContainer())
})
it("should correctly implement the entire lifecycle of an api key", async () => {
@@ -70,7 +62,7 @@ medusaIntegrationTestRunner({
expect(revoked.data.api_key).toEqual(
expect.objectContaining({
id: created.data.api_key.id,
revoked_by: "admin_user",
revoked_by: expect.stringMatching(/^user_*/),
})
)
expect(revoked.data.api_key.revoked_at).toBeTruthy()
@@ -432,19 +424,14 @@ medusaIntegrationTestRunner({
expect(deletedApiKeys.data.api_keys).toHaveLength(0)
const remoteQuery = container.resolve(
ContainerRegistrationKeys.REMOTE_QUERY
)
const fetchedSalesChannel = (
await api.get(
`/admin/sales-channels/${sales_channel.id}?fields=*publishable_api_keys`,
adminHeaders
)
).data.sales_channel
// Not the prettiest, but an easy way to check if the link was removed
const channels = await remoteQuery({
publishable_api_key_sales_channels: {
__args: { sales_channel_id: [sales_channel.id] },
fields: ["id", "sales_channel_id", "publishable_key_id"],
},
})
expect(channels).toHaveLength(0)
expect(fetchedSalesChannel.publishable_api_keys).toEqual([])
})
})
},

View File

@@ -2,12 +2,12 @@ import { medusaIntegrationTestRunner } from "medusa-test-utils"
import {
createAdminUser,
adminHeaders,
} from "../../../helpers/create-admin-user"
} from "../../../../helpers/create-admin-user"
jest.setTimeout(30000)
medusaIntegrationTestRunner({
env: { MEDUSA_FF_PRODUCT_CATEGORIES: true },
env: {},
testSuite: ({ dbConnection, getContainer, api }) => {
let baseCollection
let baseCollection1

View File

@@ -1,40 +1,51 @@
import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { createAdminUser } from "../../../helpers/create-admin-user"
import {
adminHeaders,
createAdminUser,
} from "../../../../helpers/create-admin-user"
jest.setTimeout(50000)
const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}
medusaIntegrationTestRunner({
env,
env: {},
testSuite: ({ dbConnection, getContainer, api }) => {
describe("Product categories - Admin", () => {
let container
beforeAll(async () => {
container = getContainer()
})
beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders, container)
await createAdminUser(dbConnection, adminHeaders, getContainer())
})
it("should correctly query categories by q", async () => {
const productService = container.resolve("productModuleService")
const categoryOne = await productService.createCategory({
name: "Category One",
})
const categoryTwo = await productService.createCategory({
name: "Category Two",
parent_category_id: categoryOne.id,
})
const categoryThree = await productService.createCategory({
name: "Category Three",
parent_category_id: categoryTwo.id,
})
const categoryOne = (
await api.post(
"/admin/product-categories",
{
name: "Category One",
},
adminHeaders
)
).data.product_category
const categoryTwo = (
await api.post(
"/admin/product-categories",
{
name: "Category Two",
parent_category_id: categoryOne.id,
},
adminHeaders
)
).data.product_category
const categoryThree = (
await api.post(
"/admin/product-categories",
{
name: "Category Three",
parent_category_id: categoryTwo.id,
},
adminHeaders
)
).data.product_category
const response = await api.get(
"/admin/product-categories?q=Category",