adds ability to update balance to 0 and adds integration test (#1036)
This commit is contained in:
1 parent
38b2e51cbb
commit
ff9e2e58cb
2 files changed
+31
-1
No files matched your search
@@ -144,6 +144,13 @@ describe("/admin/gift-cards", () => {
|
|||||||
currency_code: "usd",
|
currency_code: "usd",
|
||||||
tax_rate: 0,
|
tax_rate: 0,
|
||||||
})
|
})
|
||||||
|
await manager.insert(GiftCard, {
|
||||||
|
id: "gift_test",
|
||||||
|
code: "GC_TEST",
|
||||||
|
value: 20000,
|
||||||
|
balance: 20000,
|
||||||
|
region_id: "region",
|
||||||
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
throw err
|
throw err
|
||||||
@@ -155,6 +162,29 @@ describe("/admin/gift-cards", () => {
|
|||||||
await db.teardown()
|
await db.teardown()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("updates a balance", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post(
|
||||||
|
"/admin/gift-cards/gift_test",
|
||||||
|
{
|
||||||
|
balance: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: "Bearer test_token",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.gift_card.balance).toEqual(0)
|
||||||
|
})
|
||||||
|
|
||||||
it("creates a gift card", async () => {
|
it("creates a gift card", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ class GiftCardService extends BaseService {
|
|||||||
giftCard.metadata = await this.setMetadata_(giftCard.id, metadata)
|
giftCard.metadata = await this.setMetadata_(giftCard.id, metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (balance) {
|
if (typeof balance !== "undefined") {
|
||||||
if (balance < 0 || giftCard.value < balance) {
|
if (balance < 0 || giftCard.value < balance) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.INVALID_ARGUMENT,
|
MedusaError.Types.INVALID_ARGUMENT,
|
||||||
|
|||||||
Reference in new issue
Block a user