forked from medusajs/medusa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'medusajs:develop' into develop
- Loading branch information
Showing
413 changed files
with
18,140 additions
and
1,806 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@medusajs/utils": patch | ||
--- | ||
|
||
chore(utils): Improve big number decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
197
integration-tests/plugins/__tests__/api-key/admin/api-key.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
}) | ||
}) |
Oops, something went wrong.