Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashboard,medusa): Promotion Campaign fixes #7337

Merged
merged 47 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3fd882a
chore(medusa): strict zod versions in workspace
riqwan May 10, 2024
bc2bec6
feat(dashboard): add campaign create to promotion UI
riqwan May 13, 2024
da0f773
wip
riqwan May 13, 2024
d80d04d
fix(medusa): Missing middlewares export (#7289)
adrien2p May 10, 2024
ea753dd
fix(docblock-generator): fix how type names created from Zod objects …
shahednasser May 10, 2024
6b12c35
feat(api-ref): show schema of a tag (#7297)
shahednasser May 10, 2024
a7bd799
feat: Add support for sendgrid and logger notification providers (#7290)
sradevski May 11, 2024
01e6b4a
chore: add action to automatically label docs (#7284)
shahednasser May 13, 2024
2f9ec0f
docs: preparations for preview (#7267)
shahednasser May 13, 2024
0e8d6ee
chore: fix bug with form reset
riqwan May 13, 2024
f519052
chore: address reviews
riqwan May 13, 2024
cdb82ea
chore: fix specs
riqwan May 14, 2024
25efb7f
chore: loads of FE fixes + BE adds
riqwan May 15, 2024
7cccfe4
chore: merge with latest
riqwan May 15, 2024
c92ac0e
chore: add more polishes + reorg files
riqwan May 15, 2024
38a6ea5
chore: fixes to promotions modal
riqwan May 15, 2024
3a539b4
chore: cleanup
riqwan May 15, 2024
b8a02a4
chore: cleanup
riqwan May 15, 2024
0968b1b
chore: fix build
riqwan May 15, 2024
bb6e2b4
chore: fkix cart spec
riqwan May 15, 2024
5f3e967
Merge branch 'develop' into feat/promotion-campaigns
riqwan May 15, 2024
cac38f9
chore: fix module tests
riqwan May 15, 2024
76ed522
chore: fix moar tests
riqwan May 15, 2024
5dc68b8
Merge branch 'develop' into feat/promotion-campaigns
riqwan May 20, 2024
2bec79b
wip
riqwan May 21, 2024
14624d7
chore: merge with latest
riqwan May 21, 2024
e34e37a
chore: templates + fixes + migrate currency
riqwan May 21, 2024
8782ebe
Merge branch 'develop' into feat/promotion-campaigns
riqwan May 21, 2024
2779869
chore: fix build, add validation for max_quantity
riqwan May 21, 2024
8555b02
chore: allow removing campaigns
riqwan May 21, 2024
b4a03ae
chore: fix specs
riqwan May 21, 2024
2db21ea
chore: scope campaigns based on currency
riqwan May 21, 2024
4d27543
Merge branch 'develop' into feat/promotion-campaigns
olivermrbl May 21, 2024
8411950
Merge branch 'develop' into feat/promotion-campaigns
riqwan May 22, 2024
1a69dd0
remove console logs
riqwan May 22, 2024
a312a88
Merge branch 'develop' into feat/promotion-campaigns
riqwan May 22, 2024
295edd6
Merge branch 'develop' into feat/promotion-campaigns
riqwan May 22, 2024
19b8f07
Merge branch 'develop' into feat/promotion-campaigns
olivermrbl May 23, 2024
d1b1fd8
chore: add translations + update keys
riqwan May 23, 2024
b5bbf17
Merge branch 'develop' into feat/promotion-campaigns
riqwan May 23, 2024
68e3c4a
chore: move over filesfrom v2 to routes
riqwan May 23, 2024
8e1e18f
Merge branch 'develop' into feat/promotion-campaigns
riqwan May 23, 2024
b059732
chore(dashboard): Delete old translation files (#7423)
kasperkristensen May 23, 2024
dba7900
feat(dashboard,admin-sdk,admin-shared,admin-vite-plugin): Add support…
kasperkristensen May 23, 2024
8967505
chore: merge latest
riqwan May 23, 2024
681188e
temp skip specs
riqwan May 23, 2024
92cd41d
Merge branch 'develop' into feat/promotion-campaigns
riqwan May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading