-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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(medusa): variant creation with prices in productservice.create #5410
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
1c47273
ensure vairant creation in product endpoint works + integration test
pKorsholm 4c39e05
add expect statement for test
pKorsholm c0299d4
Merge branch 'develop' into fix/variant-creation-in-create-product
pKorsholm d8d03e6
update unit tests
pKorsholm d10e61e
Merge branch 'develop' into fix/variant-creation-in-create-product
pKorsholm e325597
update tests
pKorsholm 854899c
add more test
pKorsholm 7176fa9
Merge branch 'develop' into fix/variant-creation-in-create-product
pKorsholm 230045d
fix unit tests
pKorsholm 3ad2dcb
Merge branch 'develop' into fix/variant-creation-in-create-product
pKorsholm f0b3c13
Create small-eggs-search.md
olivermrbl 0fc679e
Merge branch 'develop' into fix/variant-creation-in-create-product
olivermrbl c8544eb
revert config change
pKorsholm cf221b4
Merge branch 'develop' into fix/variant-creation-in-create-product
pKorsholm 84034d4
make separate services integration test suite
pKorsholm 8568216
remove only
pKorsholm 4d33e81
rename step
pKorsholm 9802fc1
update jest config
pKorsholm 074ddd8
add database_extras
pKorsholm 6f401cd
update config
pKorsholm e5999ca
Merge branch 'develop' into fix/variant-creation-in-create-product
pKorsholm 22527f6
Merge branch 'develop' into fix/variant-creation-in-create-product
pKorsholm 4017b57
Merge branch 'develop' into fix/variant-creation-in-create-product
pKorsholm 0d5f92f
add build step
pKorsholm efd7962
Merge branch 'develop' into fix/variant-creation-in-create-product
pKorsholm e77ad65
Merge branch 'develop' into fix/variant-creation-in-create-product
pKorsholm 22a50f1
Merge branch 'develop' into fix/variant-creation-in-create-product
pKorsholm 7813e5e
proper beforeAll
pKorsholm 5c0199b
add console log
pKorsholm 7e9cc61
more logs
pKorsholm 8d18d82
add build step for specific tests
pKorsholm cf2be4e
fe:tch depth 1
pKorsholm 2119125
wrap in describe
pKorsholm de784eb
update medusaconfig
pKorsholm f8f1184
Merge branch 'develop' into fix/variant-creation-in-create-product
pKorsholm 3db7f4d
update medusaconfig
pKorsholm d501f04
retry integration config
pKorsholm 02813f6
remove services test-suite
pKorsholm 0d40fc2
undo changes
pKorsholm 5c5790e
rename integration test file
pKorsholm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,5 @@ | ||
--- | ||
"@medusajs/medusa": patch | ||
--- | ||
|
||
feat(medusa): variant creation with prices in productservice.create |
147 changes: 147 additions & 0 deletions
147
integration-tests/plugins/__tests__/services/product.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,147 @@ | ||
import path from "path" | ||
import { initDb, useDb } from "../../../environment-helpers/use-db" | ||
import { bootstrapApp } from "../../../environment-helpers/bootstrap-app" | ||
import { setPort } from "../../../environment-helpers/use-api" | ||
|
||
jest.setTimeout(30000) | ||
|
||
describe("product", () => { | ||
let dbConnection | ||
let medusaContainer | ||
let productService | ||
|
||
let express | ||
|
||
beforeAll(async () => { | ||
const cwd = path.resolve(path.join(__dirname, "..", "..")) | ||
dbConnection = await initDb({ cwd } as any) | ||
const { container, port, app } = await bootstrapApp({ cwd }) | ||
|
||
setPort(port) | ||
express = app.listen(port, () => { | ||
process.send!(port) | ||
}) | ||
|
||
medusaContainer = container | ||
}) | ||
|
||
afterAll(async () => { | ||
const db = useDb() | ||
await db.shutdown() | ||
|
||
express.close() | ||
}) | ||
|
||
afterEach(async () => { | ||
jest.clearAllMocks() | ||
const db = useDb() | ||
await db.teardown() | ||
}) | ||
|
||
describe("product service", () => { | ||
it("should create variant prices correctly in service creation", async () => { | ||
productService = medusaContainer.resolve("productService") | ||
|
||
const payload = { | ||
title: "test-product", | ||
handle: "test-product", | ||
options: [{ title: "test-option" }], | ||
variants: [ | ||
{ | ||
title: "test-variant", | ||
inventory_quantity: 10, | ||
sku: "test", | ||
options: [{ value: "large", title: "test-option" }], | ||
prices: [{ amount: "100", currency_code: "usd" }], | ||
}, | ||
], | ||
} | ||
|
||
const { id } = await productService.create(payload) | ||
|
||
const result = await productService.retrieve(id, { | ||
relations: ["variants", "variants.prices", "variants.options"], | ||
}) | ||
|
||
expect(result).toEqual( | ||
expect.objectContaining({ | ||
variants: [ | ||
expect.objectContaining({ | ||
options: [expect.objectContaining({ value: "large" })], | ||
prices: [ | ||
expect.objectContaining({ amount: 100, currency_code: "usd" }), | ||
], | ||
}), | ||
], | ||
}) | ||
) | ||
}) | ||
|
||
it("should fail to create a variant without options on for a product with options", async () => { | ||
const payload = { | ||
title: "test-product", | ||
handle: "test-product", | ||
options: [{ title: "test-option" }], | ||
variants: [ | ||
{ | ||
title: "test-variant", | ||
inventory_quantity: 10, | ||
sku: "test", | ||
prices: [{ amount: "100", currency_code: "usd" }], | ||
}, | ||
], | ||
} | ||
|
||
let error | ||
|
||
try { | ||
await productService.create(payload) | ||
} catch (err) { | ||
error = err | ||
} | ||
|
||
expect(error.message).toEqual( | ||
"Product options length does not match variant options length. Product has 1 and variant has 0." | ||
) | ||
}) | ||
|
||
it("should create a product and variant without options", async () => { | ||
const payload = { | ||
title: "test-product", | ||
handle: "test-product", | ||
variants: [ | ||
{ | ||
title: "test-variant", | ||
inventory_quantity: 10, | ||
sku: "test", | ||
prices: [{ amount: "100", currency_code: "usd" }], | ||
}, | ||
], | ||
} | ||
|
||
const { id } = await productService.create(payload) | ||
|
||
const result = await productService.retrieve(id, { | ||
relations: [ | ||
"options", | ||
"variants", | ||
"variants.prices", | ||
"variants.options", | ||
], | ||
}) | ||
|
||
expect(result).toEqual( | ||
expect.objectContaining({ | ||
options: [], | ||
variants: [ | ||
expect.objectContaining({ | ||
prices: [ | ||
expect.objectContaining({ amount: 100, currency_code: "usd" }), | ||
], | ||
}), | ||
], | ||
}) | ||
) | ||
}) | ||
}) | ||
}) |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment(this-file): Something is off about having integration tests for core services in the plugins directory. I think we should move this to API (even though not ideal either) to have it closer to the core. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, however there's something about having the redis_url in the project config of the api that breaks the
bootstrapApp({ cwd })
method for server setup, though it's needed to get the container