Skip to content

Commit

Permalink
feat(dashboard,medusa): Promotion Campaign fixes (#7337)
Browse files Browse the repository at this point in the history
* chore(medusa): strict zod versions in workspace

* feat(dashboard): add campaign create to promotion UI

* wip

* fix(medusa): Missing middlewares export (#7289)

* fix(docblock-generator): fix how type names created from Zod objects are inferred (#7292)

* feat(api-ref): show schema of a tag (#7297)

* feat: Add support for sendgrid and logger notification providers (#7290)

* feat: Add support for sendgrid and logger notification providers

* fix: changes based on PR review

* chore: add action to automatically label docs (#7284)

* chore: add action to automatically label docs

* removes the paths param

* docs: preparations for preview (#7267)

* configured base paths + added development banner

* fix typelist site url

* added navbar and sidebar badges

* configure algolia filters

* remove AI assistant

* remove unused imports

* change navbar text and badge

* lint fixes

* fix build error

* add to api reference rewrites

* fix build error

* fix build errors in user-guide

* fix feedback component

* add parent title to pagination

* added breadcrumbs component

* remove user-guide links

* resolve todos

* fix details about authentication

* change documentation title

* lint content

* chore: fix bug with form reset

* chore: address reviews

* chore: fix specs

* chore: loads of FE fixes + BE adds

* chore: add more polishes + reorg files

* chore: fixes to promotions modal

* chore: cleanup

* chore: cleanup

* chore: fix build

* chore: fkix cart spec

* chore: fix module tests

* chore: fix moar tests

* wip

* chore: templates + fixes + migrate currency

* chore: fix build, add validation for max_quantity

* chore: allow removing campaigns

* chore: fix specs

* chore: scope campaigns based on currency

* remove console logs

* chore: add translations + update keys

* chore: move over filesfrom v2 to routes

* chore(dashboard): Delete old translation files (#7423)

* feat(dashboard,admin-sdk,admin-shared,admin-vite-plugin): Add support for UI extensions (#7383)

* intial work

* update lock

* add routes and fix HMR of configs

* cleanup

* rm imports

* rm debug from plugin

* address feedback

* address feedback

* temp skip specs

---------

Co-authored-by: Adrien de Peretti <[email protected]>
Co-authored-by: Shahed Nasser <[email protected]>
Co-authored-by: Stevche Radevski <[email protected]>
Co-authored-by: Oli Juhl <[email protected]>
Co-authored-by: Kasper Fabricius Kristensen <[email protected]>
  • Loading branch information
6 people authored May 23, 2024
1 parent 4a10821 commit d1d23f1
Show file tree
Hide file tree
Showing 72 changed files with 5,407 additions and 3,500 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ medusaIntegrationTestRunner({
allocation: "each",
value: "300",
apply_to_quantity: 1,
currency_code: "usd",
max_quantity: 1,
target_rules: [
{
Expand All @@ -69,6 +70,7 @@ medusaIntegrationTestRunner({
allocation: "across",
value: "1000",
apply_to_quantity: 1,
currency_code: "usd",
target_rules: [
{
attribute: "product_id",
Expand Down Expand Up @@ -172,6 +174,7 @@ medusaIntegrationTestRunner({
allocation: "each",
value: "100",
max_quantity: 1,
currency_code: "usd",
target_rules: [
{
attribute: "name",
Expand Down Expand Up @@ -205,6 +208,7 @@ medusaIntegrationTestRunner({
allocation: "each",
value: "200",
max_quantity: 1,
currency_code: "usd",
target_rules: [
{
attribute: "name",
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/modules/__tests__/cart/store/carts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ medusaIntegrationTestRunner({
target_type: "items",
allocation: "each",
value: 300,
currency_code: "usd",
apply_to_quantity: 1,
max_quantity: 1,
target_rules: targetRules,
Expand All @@ -547,6 +548,7 @@ medusaIntegrationTestRunner({
type: "fixed",
target_type: "items",
allocation: "across",
currency_code: "usd",
value: 1000,
apply_to_quantity: 1,
target_rules: targetRules,
Expand Down Expand Up @@ -1232,6 +1234,7 @@ medusaIntegrationTestRunner({
allocation: "across",
value: 300,
apply_to_quantity: 2,
currency_code: "usd",
target_rules: [
{
attribute: "product_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ medusaIntegrationTestRunner({
allocation: "each",
value: "300",
apply_to_quantity: 1,
currency_code: "usd",
max_quantity: 1,
target_rules: [
{
Expand All @@ -69,6 +70,7 @@ medusaIntegrationTestRunner({
allocation: "each",
value: "300",
apply_to_quantity: 1,
currency_code: "usd",
max_quantity: 1,
target_rules: [
{
Expand Down Expand Up @@ -189,6 +191,7 @@ medusaIntegrationTestRunner({
allocation: "each",
value: "100",
max_quantity: 1,
currency_code: "usd",
target_rules: [
{
attribute: "name",
Expand Down Expand Up @@ -220,6 +223,7 @@ medusaIntegrationTestRunner({
allocation: "each",
value: "100",
max_quantity: 1,
currency_code: "usd",
target_rules: [
{
attribute: "name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ jest.setTimeout(50000)
export const campaignData = {
name: "campaign 1",
description: "test description",
currency: "USD",
campaign_identifier: "test-1",
starts_at: new Date("01/01/2023").toISOString(),
ends_at: new Date("01/01/2024").toISOString(),
budget: {
type: CampaignBudgetType.SPEND,
limit: 1000,
used: 0,
currency_code: "USD",
},
}

Expand All @@ -25,32 +24,57 @@ export const campaignsData = [
id: "campaign-id-1",
name: "campaign 1",
description: "test description",
currency: "USD",
campaign_identifier: "test-1",
starts_at: new Date("01/01/2023"),
ends_at: new Date("01/01/2024"),
budget: {
type: CampaignBudgetType.SPEND,
limit: 1000,
used: 0,
currency_code: "USD",
},
},
{
id: "campaign-id-2",
name: "campaign 2",
description: "test description",
currency: "USD",
campaign_identifier: "test-2",
starts_at: new Date("01/01/2023"),
ends_at: new Date("01/01/2024"),
budget: {
type: CampaignBudgetType.USAGE,
limit: 1000,
used: 0,
},
},
]

const promotionData = {
code: "TEST",
type: PromotionType.STANDARD,
is_automatic: true,
application_method: {
target_type: "items",
type: "fixed",
allocation: "each",
currency_code: "USD",
value: 100,
max_quantity: 100,
target_rules: [
{
attribute: "test.test",
operator: "eq",
values: ["test1", "test2"],
},
],
},
rules: [
{
attribute: "test.test",
operator: "eq",
values: ["test1", "test2"],
},
],
}

const env = { MEDUSA_FF_MEDUSA_V2: true }
const adminHeaders = {
headers: { "x-medusa-access-token": "test_token" },
Expand Down Expand Up @@ -88,6 +112,7 @@ medusaIntegrationTestRunner({
value: 100,
max_quantity: 100,
target_rules: [],
currency_code: "USD",
},
rules: [],
}
Expand All @@ -109,13 +134,13 @@ medusaIntegrationTestRunner({
id: expect.any(String),
name: "campaign 1",
description: "test description",
currency: "USD",
campaign_identifier: "test-1",
starts_at: expect.any(String),
ends_at: expect.any(String),
budget: {
id: expect.any(String),
type: "spend",
currency_code: "USD",
limit: 1000,
used: 0,
raw_limit: {
Expand All @@ -138,7 +163,6 @@ medusaIntegrationTestRunner({
id: expect.any(String),
name: "campaign 2",
description: "test description",
currency: "USD",
campaign_identifier: "test-2",
starts_at: expect.any(String),
ends_at: expect.any(String),
Expand All @@ -147,6 +171,7 @@ medusaIntegrationTestRunner({
type: "usage",
limit: 1000,
used: 0,
currency_code: null,
raw_limit: {
precision: 20,
value: "1000",
Expand Down Expand Up @@ -239,14 +264,14 @@ medusaIntegrationTestRunner({
id: expect.any(String),
name: "campaign 1",
description: "test description",
currency: "USD",
campaign_identifier: "test-1",
starts_at: expect.any(String),
ends_at: expect.any(String),
budget: {
id: expect.any(String),
type: "spend",
limit: 1000,
currency_code: "USD",
raw_limit: {
precision: 20,
value: "1000",
Expand Down Expand Up @@ -297,11 +322,6 @@ medusaIntegrationTestRunner({
})

it("should create a campaign successfully", async () => {
const createdPromotion = await promotionModuleService.create({
code: "TEST",
type: "standard",
})

const response = await api.post(
`/admin/campaigns?fields=*promotions`,
{
Expand Down Expand Up @@ -334,10 +354,11 @@ medusaIntegrationTestRunner({
})

it("should create 3 campaigns in parallel and have the context passed as argument when calling createCampaigns with different transactionId", async () => {
const parallelPromotion = await promotionModuleService.create({
code: "PARALLEL",
type: "standard",
})
await api.post(
`/admin/promotions`,
{ ...promotionData, code: "PARALLEL" },
adminHeaders
)

const spyCreateCampaigns = jest.spyOn(
promotionModuleService.constructor.prototype,
Expand Down Expand Up @@ -438,22 +459,26 @@ medusaIntegrationTestRunner({
})

it("should update a campaign successfully", async () => {
const createdPromotion = await promotionModuleService.create({
code: "TEST",
type: "standard",
})
const createdPromotion = (
await api.post(`/admin/promotions`, promotionData, adminHeaders)
).data.promotion

const createdCampaign = await promotionModuleService.createCampaigns({
name: "test",
campaign_identifier: "test",
starts_at: new Date("01/01/2024").toISOString(),
ends_at: new Date("01/01/2029").toISOString(),
budget: {
limit: 1000,
type: "usage",
used: 10,
},
})
const createdCampaign = (
await api.post(
`/admin/campaigns`,
{
name: "test",
campaign_identifier: "test",
starts_at: new Date("01/01/2024").toISOString(),
ends_at: new Date("01/01/2029").toISOString(),
budget: {
limit: 1000,
type: "usage",
},
},
adminHeaders
)
).data.campaign

await promotionModuleService.addPromotionsToCampaign({
id: createdCampaign.id,
Expand Down Expand Up @@ -481,7 +506,6 @@ medusaIntegrationTestRunner({
budget: expect.objectContaining({
limit: 2000,
type: "usage",
used: 10,
}),
promotions: [
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ medusaIntegrationTestRunner({
target_type: "items",
type: "fixed",
allocation: "each",
currency_code: "USD",
value: 100,
max_quantity: 100,
target_rules: [
Expand Down Expand Up @@ -97,6 +98,7 @@ medusaIntegrationTestRunner({
name: "test",
campaign_identifier: "test-1",
budget: expect.objectContaining({
currency_code: null,
type: "usage",
limit: 100,
}),
Expand Down Expand Up @@ -146,6 +148,7 @@ medusaIntegrationTestRunner({
allocation: "each",
value: 100,
max_quantity: 100,
currency_code: "USD",
target_rules: [
{
attribute: "test.test",
Expand Down Expand Up @@ -186,6 +189,7 @@ medusaIntegrationTestRunner({
allocation: "each",
value: 100,
max_quantity: 100,
currency_code: "USD",
buy_rules: [
{
attribute: "test.test",
Expand Down Expand Up @@ -235,6 +239,7 @@ medusaIntegrationTestRunner({
max_quantity: 100,
apply_to_quantity: 1,
buy_rules_min_quantity: 1,
currency_code: "USD",
target_rules: [
{
attribute: "test.test",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IPromotionModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { createAdminUser } from "../../../../helpers/create-admin-user"
import { IPromotionModuleService } from "@medusajs/types"
import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { createAdminUser } from "../../../../helpers/create-admin-user"

jest.setTimeout(50000)

Expand Down Expand Up @@ -36,6 +36,7 @@ medusaIntegrationTestRunner({
type: "fixed",
target_type: "order",
value: "100",
currency_code: "USD",
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ medusaIntegrationTestRunner({
type: "fixed",
target_type: "order",
value: 100,
currency_code: "USD",
},
},
])
Expand Down Expand Up @@ -76,6 +77,7 @@ medusaIntegrationTestRunner({
type: "fixed",
target_type: "order",
value: 100,
currency_code: "USD",
},
},
{
Expand All @@ -85,6 +87,7 @@ medusaIntegrationTestRunner({
type: "fixed",
target_type: "order",
value: 100,
currency_code: "USD",
},
},
])
Expand All @@ -108,6 +111,7 @@ medusaIntegrationTestRunner({
type: "fixed",
target_type: "order",
value: 100,
currency_code: "USD",
},
},
])
Expand Down
Loading

0 comments on commit d1d23f1

Please sign in to comment.