Skip to content

Commit

Permalink
Merge branch 'medusajs:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
driver005 authored Feb 27, 2024
2 parents d1b5546 + 70aeb60 commit 5c11986
Show file tree
Hide file tree
Showing 413 changed files with 18,140 additions and 1,806 deletions.
8 changes: 8 additions & 0 deletions .changeset/clean-llamas-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@medusajs/workflows-sdk": patch
"@medusajs/core-flows": patch
"@medusajs/medusa": patch
"@medusajs/types": patch
---

feat(workflows-sdk,core-flows,medusa,types): add workflow to add promotions to cart
5 changes: 5 additions & 0 deletions .changeset/fair-baboons-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/utils": patch
---

chore(utils): Soft delete should allow self referencing circular deps
2 changes: 2 additions & 0 deletions .changeset/green-geckos-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
5 changes: 5 additions & 0 deletions .changeset/honest-poets-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/utils": patch
---

chore(utils): Improve big number decorator
5 changes: 5 additions & 0 deletions .changeset/itchy-bags-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/utils": patch
---

fix(utils): bignumber util considers nullable options when setting value
5 changes: 5 additions & 0 deletions .changeset/loud-mirrors-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/types": patch
---

feat(fulfillment): List shipping options filtered by context and rules
5 changes: 5 additions & 0 deletions .changeset/polite-papayas-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): add `order` param to discounts list
5 changes: 5 additions & 0 deletions .changeset/rude-knives-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/utils": patch
---

chore(util): Detect circular dependencies on soft delete
8 changes: 8 additions & 0 deletions .changeset/shiny-avocados-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@medusajs/core-flows": patch
"@medusajs/medusa": patch
"@medusajs/types": patch
"@medusajs/utils": patch
---

feat(core-flows,medusa,types,utils): adds update cart API with promotions
7 changes: 7 additions & 0 deletions .changeset/swift-frogs-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@medusajs/medusa": patch
"@medusajs/types": patch
"@medusajs/utils": patch
---

feat(payment-stripe): new Stripe payment provider
197 changes: 197 additions & 0 deletions integration-tests/plugins/__tests__/api-key/admin/api-key.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import { initDb, useDb } from "../../../../environment-helpers/use-db"

import { ApiKeyType } from "@medusajs/utils"
import { IApiKeyModuleService, IRegionModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../../helpers/create-admin-user"
import { getContainer } from "../../../../environment-helpers/use-container"
import path from "path"
import { startBootstrapApp } from "../../../../environment-helpers/bootstrap-app"
import { useApi } from "../../../../environment-helpers/use-api"

jest.setTimeout(50000)

const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
}

describe("API Keys - Admin", () => {
let dbConnection
let appContainer
let shutdownServer
let service: IApiKeyModuleService
let regionService: IRegionModuleService

beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
dbConnection = await initDb({ cwd, env } as any)
shutdownServer = await startBootstrapApp({ cwd, env })
appContainer = getContainer()
service = appContainer.resolve(ModuleRegistrationName.API_KEY)
regionService = appContainer.resolve(ModuleRegistrationName.REGION)
})

afterAll(async () => {
const db = useDb()
await db.shutdown()
await shutdownServer()
})

beforeEach(async () => {
await createAdminUser(dbConnection, adminHeaders)

// Used for testing cross-module authentication checks
await regionService.createDefaultCountriesAndCurrencies()
})

afterEach(async () => {
const db = useDb()
await db.teardown()
})

it("should correctly implement the entire lifecycle of an api key", async () => {
const api = useApi() as any
const created = await api.post(
`/admin/api-keys`,
{
title: "Test Secret Key",
type: ApiKeyType.SECRET,
},
adminHeaders
)

expect(created.status).toEqual(200)
expect(created.data.apiKey).toEqual(
expect.objectContaining({
id: created.data.apiKey.id,
title: "Test Secret Key",
created_by: "admin_user",
})
)
// On create we get the token in raw form so we can store it.
expect(created.data.apiKey.token).toContain("sk_")

const updated = await api.post(
`/admin/api-keys/${created.data.apiKey.id}`,
{
title: "Updated Secret Key",
},
adminHeaders
)

expect(updated.status).toEqual(200)
expect(updated.data.apiKey).toEqual(
expect.objectContaining({
id: created.data.apiKey.id,
title: "Updated Secret Key",
})
)

const revoked = await api.post(
`/admin/api-keys/${created.data.apiKey.id}/revoke`,
{},
adminHeaders
)

expect(revoked.status).toEqual(200)
expect(revoked.data.apiKey).toEqual(
expect.objectContaining({
id: created.data.apiKey.id,
revoked_by: "admin_user",
})
)
expect(revoked.data.apiKey.revoked_at).toBeTruthy()

const deleted = await api.delete(
`/admin/api-keys/${created.data.apiKey.id}`,
adminHeaders
)
const listedApiKeys = await api.get(`/admin/api-keys`, adminHeaders)

expect(deleted.status).toEqual(200)
expect(listedApiKeys.data.apiKeys).toHaveLength(0)
})

it("can use a secret api key for authentication", async () => {
const api = useApi() as any
const created = await api.post(
`/admin/api-keys`,
{
title: "Test Secret Key",
type: ApiKeyType.SECRET,
},
adminHeaders
)

const createdRegion = await api.post(
`/admin/regions`,
{
name: "Test Region",
currency_code: "usd",
countries: ["us", "ca"],
},
{
auth: {
username: created.data.apiKey.token,
},
}
)

expect(createdRegion.status).toEqual(200)
expect(createdRegion.data.region.name).toEqual("Test Region")
})

it("falls back to other mode of authentication when an api key is not valid", async () => {
const api = useApi() as any
const created = await api.post(
`/admin/api-keys`,
{
title: "Test Secret Key",
type: ApiKeyType.SECRET,
},
adminHeaders
)

await api.post(
`/admin/api-keys/${created.data.apiKey.id}/revoke`,
{},
adminHeaders
)

const err = await api
.post(
`/admin/regions`,
{
name: "Test Region",
currency_code: "usd",
countries: ["us", "ca"],
},
{
auth: {
username: created.data.apiKey.token,
},
}
)
.catch((e) => e.message)

const createdRegion = await api.post(
`/admin/regions`,
{
name: "Test Region",
currency_code: "usd",
countries: ["us", "ca"],
},
{
auth: {
username: created.data.apiKey.token,
},
...adminHeaders,
}
)

expect(err).toEqual("Request failed with status code 401")
expect(createdRegion.status).toEqual(200)
expect(createdRegion.data.region.name).toEqual("Test Region")
})
})
Loading

0 comments on commit 5c11986

Please sign in to comment.