test: add tests

This commit is contained in:
Harminder Virk
2024-05-17 09:33:34 +05:30
parent 9298a57be1
commit a15f2b37b3
@@ -365,6 +365,73 @@ moduleIntegrationTestRunner({
"ProductCollection with id: does-not-exist was not found"
)
})
it("should dissociate existing products when new products are synced", async () => {
await service.upsertCollections([
{
id: collectionId,
product_ids: [productOne.id, productTwo.id],
},
])
/**
* Another upsert should remove the first productOne
*/
await service.upsertCollections([
{
id: collectionId,
product_ids: [productTwo.id],
},
])
const productCollection = await service.retrieveCollection(
collectionId,
{
select: ["products.id"],
relations: ["products"],
}
)
expect(productCollection.products).toHaveLength(1)
expect(productCollection).toEqual(
expect.objectContaining({
products: expect.arrayContaining([
expect.objectContaining({
id: productTwo.id,
}),
]),
})
)
})
it("should dissociate all existing products", async () => {
await service.upsertCollections([
{
id: collectionId,
product_ids: [productOne.id, productTwo.id],
},
])
/**
* Another upsert should remove the first productOne
*/
await service.upsertCollections([
{
id: collectionId,
product_ids: [],
},
])
const productCollection = await service.retrieveCollection(
collectionId,
{
select: ["products.id"],
relations: ["products"],
}
)
expect(productCollection.products).toHaveLength(0)
})
})
describe("createCollections", () => {