chore: Move currency, collection, and auth tests to http folder (#7581)
* chore: Move auth tests to http folder * chore: Migrate collection tests to http folder * chore: Move currency tests to http folder
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
beforeEach(async () => {
|
||||
await createAdminUser(dbConnection, adminHeaders, getContainer())
|
||||
})
|
||||
|
||||
it.only("test the entire authentication flow", async () => {
|
||||
// BREAKING: `/admin/auth` changes to `/auth/user/emailpass`
|
||||
const signup = await api.post("/auth/user/emailpass", {
|
||||
email: "newadmin@medusa.js",
|
||||
password: "secret_password",
|
||||
})
|
||||
|
||||
//BREAKING: In V2, we respond with a JWT token instead of the user object, and a session is not created. you need to call `/auth/session` to create a session
|
||||
expect(signup.status).toEqual(200)
|
||||
expect(signup.data).toEqual({ token: expect.any(String) })
|
||||
|
||||
// BREAKING: IN V2 creating a user is separated from creating an auth identity
|
||||
const createdUser = await api.post(
|
||||
"/admin/users",
|
||||
{ email: "newadmin@medusa.js" },
|
||||
{ headers: { authorization: `Bearer ${signup.data.token}` } }
|
||||
)
|
||||
expect(createdUser.status).toEqual(200)
|
||||
expect(createdUser.data.user.email).toEqual("newadmin@medusa.js")
|
||||
|
||||
const login = await api.post("/auth/user/emailpass", {
|
||||
email: "newadmin@medusa.js",
|
||||
password: "secret_password",
|
||||
})
|
||||
expect(login.status).toEqual(200)
|
||||
expect(login.data).toEqual({ token: expect.any(String) })
|
||||
|
||||
const createSession = await api.post(
|
||||
"/auth/session",
|
||||
{},
|
||||
{ headers: { authorization: `Bearer ${login.data.token}` } }
|
||||
)
|
||||
expect(createSession.status).toEqual(200)
|
||||
|
||||
// extract cookie
|
||||
const [cookie] = createSession.headers["set-cookie"][0].split(";")
|
||||
expect(cookie).toEqual(expect.stringContaining("connect.sid"))
|
||||
|
||||
const cookieHeader = {
|
||||
headers: { Cookie: cookie },
|
||||
}
|
||||
|
||||
// perform cookie authenticated request
|
||||
const authedRequest = await api.get(
|
||||
"/admin/products?limit=1",
|
||||
cookieHeader
|
||||
)
|
||||
expect(authedRequest.status).toEqual(200)
|
||||
|
||||
// sign out
|
||||
const signOutRequest = await api.delete("/auth/session", cookieHeader)
|
||||
expect(signOutRequest.status).toEqual(200)
|
||||
|
||||
// attempt to perform authenticated request
|
||||
const unAuthedRequest = await api
|
||||
.get("/admin/products?limit=1", cookieHeader)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(unAuthedRequest.response.status).toEqual(401)
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,262 @@
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
createAdminUser,
|
||||
adminHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env: {},
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
let baseCollection
|
||||
let baseCollection1
|
||||
let baseCollection2
|
||||
|
||||
let baseProduct
|
||||
let baseProduct1
|
||||
|
||||
beforeEach(async () => {
|
||||
const container = getContainer()
|
||||
await createAdminUser(dbConnection, adminHeaders, container)
|
||||
|
||||
baseCollection = (
|
||||
await api.post(
|
||||
"/admin/collections",
|
||||
{ title: "test-collection" },
|
||||
adminHeaders
|
||||
)
|
||||
).data.collection
|
||||
|
||||
baseCollection1 = (
|
||||
await api.post(
|
||||
"/admin/collections",
|
||||
{ title: "test-collection1" },
|
||||
adminHeaders
|
||||
)
|
||||
).data.collection
|
||||
|
||||
baseCollection2 = (
|
||||
await api.post(
|
||||
"/admin/collections",
|
||||
{ title: "test-collection2" },
|
||||
adminHeaders
|
||||
)
|
||||
).data.collection
|
||||
|
||||
baseProduct = (
|
||||
await api.post(
|
||||
"/admin/products",
|
||||
{
|
||||
title: "test-product",
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
).data.product
|
||||
|
||||
baseProduct1 = (
|
||||
await api.post(
|
||||
"/admin/products",
|
||||
{
|
||||
title: "test-product1",
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
).data.product
|
||||
})
|
||||
|
||||
describe("/admin/collections", () => {
|
||||
it("creates a collection", async () => {
|
||||
const response = await api.post(
|
||||
"/admin/collections",
|
||||
{
|
||||
title: "New collection",
|
||||
handle: "test-new-collection",
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
collection: expect.objectContaining({
|
||||
id: expect.stringMatching(/^pcol_*/),
|
||||
title: "New collection",
|
||||
handle: "test-new-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("lists collections", async () => {
|
||||
const response = await api.get("/admin/collections", adminHeaders)
|
||||
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
count: 3,
|
||||
collections: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: baseCollection2.id,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: baseCollection1.id,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: baseCollection.id,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("filters collections by title", async () => {
|
||||
const response = await api.get(
|
||||
"/admin/collections?title=test-collection",
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
count: 1,
|
||||
collections: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: baseCollection.id,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
// BREAKING: There is no longer discount condition ID filtering for collections (test case: "returns a list of collections filtered by discount condition id")
|
||||
})
|
||||
|
||||
describe("/admin/collections/:id", () => {
|
||||
it("updates a collection", async () => {
|
||||
const response = await api.post(
|
||||
`/admin/collections/${baseCollection.id}`,
|
||||
{
|
||||
title: "test collection creation",
|
||||
handle: "test-handle-creation",
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
collection: expect.objectContaining({
|
||||
id: expect.stringMatching(/^pcol_*/),
|
||||
title: "test collection creation",
|
||||
handle: "test-handle-creation",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("deletes a collection", async () => {
|
||||
const response = await api.delete(
|
||||
`/admin/collections/${baseCollection.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual({
|
||||
id: baseCollection.id,
|
||||
object: "collection",
|
||||
deleted: true,
|
||||
})
|
||||
})
|
||||
|
||||
it("gets collection", async () => {
|
||||
const response = await api.get(
|
||||
`/admin/collections/${baseCollection.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
collection: expect.objectContaining({
|
||||
id: baseCollection.id,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
// BREAKING: URL and payload changes for adding products to a collection (there is no more "batch" suffix)
|
||||
it("adds products to collection", async () => {
|
||||
const response = await api.post(
|
||||
`/admin/collections/${baseCollection.id}/products?fields=*products`,
|
||||
{
|
||||
add: [baseProduct.id, baseProduct1.id],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.collection).toEqual(
|
||||
expect.objectContaining({
|
||||
id: baseCollection.id,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
collection_id: baseCollection.id,
|
||||
title: "test-product",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
collection_id: baseCollection.id,
|
||||
title: "test-product1",
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("removes products from collection", async () => {
|
||||
await api.post(
|
||||
`/admin/collections/${baseCollection.id}/products`,
|
||||
{
|
||||
add: [baseProduct.id, baseProduct1.id],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/collections/${baseCollection.id}/products?fields=*products`,
|
||||
{
|
||||
remove: [baseProduct1.id],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.data.collection).toEqual(
|
||||
expect.objectContaining({
|
||||
id: baseCollection.id,
|
||||
products: [
|
||||
expect.objectContaining({
|
||||
collection_id: baseCollection.id,
|
||||
title: "test-product",
|
||||
}),
|
||||
],
|
||||
})
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,66 @@
|
||||
import { medusaIntegrationTestRunner } from "medusa-test-utils"
|
||||
import {
|
||||
createAdminUser,
|
||||
adminHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
env: {},
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
beforeEach(async () => {
|
||||
const container = getContainer()
|
||||
await createAdminUser(dbConnection, adminHeaders, container)
|
||||
})
|
||||
|
||||
describe("GET /admin/currencies", () => {
|
||||
it("should retrieve the currencies", async () => {
|
||||
const response = await api.get(
|
||||
"/admin/currencies?order=code",
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.currencies).toHaveLength(120)
|
||||
expect(response.data.currencies).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
code: "usd",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("should retrieve the currencies filtered with q param", async () => {
|
||||
const response = await api.get(
|
||||
`/admin/currencies?q=us&order=code`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.currencies).toEqual([
|
||||
expect.objectContaining({
|
||||
code: "aud",
|
||||
name: "Australian Dollar",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "byn",
|
||||
name: "Belarusian Ruble",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "rub",
|
||||
name: "Russian Ruble",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
code: "usd",
|
||||
name: "US Dollar",
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
// BREAKING: There was an "should update currency includes_tax" test that no longer applies in v2 (realted to MEDUSA_FF_TAX_INCLUSIVE_PRICING)
|
||||
})
|
||||
Reference in New Issue
Block a user