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:
1 parent
e66cf9112d
commit
294ec36cc3
4 files changed
+47
-105
No files matched your search
@@ -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"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
+13
-26
@@ -1,26 +1,18 @@
|
|||||||
import { ApiKeyType, ContainerRegistrationKeys } from "@medusajs/utils"
|
import { ApiKeyType, ContainerRegistrationKeys } from "@medusajs/utils"
|
||||||
import { medusaIntegrationTestRunner } from "medusa-test-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)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
|
||||||
const adminHeaders = {
|
|
||||||
headers: { "x-medusa-access-token": "test_token" },
|
|
||||||
}
|
|
||||||
|
|
||||||
medusaIntegrationTestRunner({
|
medusaIntegrationTestRunner({
|
||||||
env,
|
env: {},
|
||||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
describe("API Keys - Admin", () => {
|
describe("API Keys - Admin", () => {
|
||||||
let container
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
container = getContainer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders, container)
|
await createAdminUser(dbConnection, adminHeaders, getContainer())
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should correctly implement the entire lifecycle of an api key", async () => {
|
it("should correctly implement the entire lifecycle of an api key", async () => {
|
||||||
@@ -70,7 +62,7 @@ medusaIntegrationTestRunner({
|
|||||||
expect(revoked.data.api_key).toEqual(
|
expect(revoked.data.api_key).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: created.data.api_key.id,
|
id: created.data.api_key.id,
|
||||||
revoked_by: "admin_user",
|
revoked_by: expect.stringMatching(/^user_*/),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
expect(revoked.data.api_key.revoked_at).toBeTruthy()
|
expect(revoked.data.api_key.revoked_at).toBeTruthy()
|
||||||
@@ -432,19 +424,14 @@ medusaIntegrationTestRunner({
|
|||||||
|
|
||||||
expect(deletedApiKeys.data.api_keys).toHaveLength(0)
|
expect(deletedApiKeys.data.api_keys).toHaveLength(0)
|
||||||
|
|
||||||
const remoteQuery = container.resolve(
|
const fetchedSalesChannel = (
|
||||||
ContainerRegistrationKeys.REMOTE_QUERY
|
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
|
expect(fetchedSalesChannel.publishable_api_keys).toEqual([])
|
||||||
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)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
+2
-2
@@ -2,12 +2,12 @@ import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
|||||||
import {
|
import {
|
||||||
createAdminUser,
|
createAdminUser,
|
||||||
adminHeaders,
|
adminHeaders,
|
||||||
} from "../../../helpers/create-admin-user"
|
} from "../../../../helpers/create-admin-user"
|
||||||
|
|
||||||
jest.setTimeout(30000)
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
medusaIntegrationTestRunner({
|
medusaIntegrationTestRunner({
|
||||||
env: { MEDUSA_FF_PRODUCT_CATEGORIES: true },
|
env: {},
|
||||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
let baseCollection
|
let baseCollection
|
||||||
let baseCollection1
|
let baseCollection1
|
||||||
+32
-21
@@ -1,40 +1,51 @@
|
|||||||
import { medusaIntegrationTestRunner } from "medusa-test-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)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
const env = { MEDUSA_FF_MEDUSA_V2: true }
|
|
||||||
const adminHeaders = {
|
|
||||||
headers: { "x-medusa-access-token": "test_token" },
|
|
||||||
}
|
|
||||||
|
|
||||||
medusaIntegrationTestRunner({
|
medusaIntegrationTestRunner({
|
||||||
env,
|
env: {},
|
||||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||||
describe("Product categories - Admin", () => {
|
describe("Product categories - Admin", () => {
|
||||||
let container
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
container = getContainer()
|
|
||||||
})
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders, container)
|
await createAdminUser(dbConnection, adminHeaders, getContainer())
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should correctly query categories by q", async () => {
|
it("should correctly query categories by q", async () => {
|
||||||
const productService = container.resolve("productModuleService")
|
const categoryOne = (
|
||||||
const categoryOne = await productService.createCategory({
|
await api.post(
|
||||||
|
"/admin/product-categories",
|
||||||
|
{
|
||||||
name: "Category One",
|
name: "Category One",
|
||||||
})
|
},
|
||||||
const categoryTwo = await productService.createCategory({
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.product_category
|
||||||
|
|
||||||
|
const categoryTwo = (
|
||||||
|
await api.post(
|
||||||
|
"/admin/product-categories",
|
||||||
|
{
|
||||||
name: "Category Two",
|
name: "Category Two",
|
||||||
parent_category_id: categoryOne.id,
|
parent_category_id: categoryOne.id,
|
||||||
})
|
},
|
||||||
const categoryThree = await productService.createCategory({
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.product_category
|
||||||
|
|
||||||
|
const categoryThree = (
|
||||||
|
await api.post(
|
||||||
|
"/admin/product-categories",
|
||||||
|
{
|
||||||
name: "Category Three",
|
name: "Category Three",
|
||||||
parent_category_id: categoryTwo.id,
|
parent_category_id: categoryTwo.id,
|
||||||
})
|
},
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.product_category
|
||||||
|
|
||||||
const response = await api.get(
|
const response = await api.get(
|
||||||
"/admin/product-categories?q=Category",
|
"/admin/product-categories?q=Category",
|
||||||
Reference in new issue
Block a user