-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from reactioncommerce/fix-mohan-33-query-with-…
…cartid-and-accesstoken Query with cartId and accessToken. Unit tests.
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
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
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,37 @@ | ||
import mockContext from "@reactioncommerce/api-utils/tests/mockContext.js"; | ||
import hashToken from "@reactioncommerce/api-utils/hashToken.js"; | ||
import anonymousCartByCartId from "./anonymousCartByCartId.js"; | ||
|
||
test("query anonymous cart", async () => { | ||
const cartId = "123"; | ||
const cartToken = "xyz"; | ||
const cart = { | ||
_id: cartId, | ||
anonymousAccessToken: cartToken | ||
}; | ||
const callingParams = { | ||
_id: cartId, | ||
anonymousAccessToken: hashToken(cartToken) | ||
}; | ||
|
||
mockContext.collections.Cart.findOne.mockReturnValueOnce(Promise.resolve(cart)); | ||
|
||
const result = await anonymousCartByCartId(mockContext, { cartId, cartToken }); | ||
expect(result).toEqual(cart); | ||
expect(mockContext.collections.Cart.findOne).toHaveBeenCalledWith(callingParams); | ||
}); | ||
|
||
test("query without hashed access token", async () => { | ||
const cartId = "123"; | ||
const cartToken = "xyz"; | ||
const callingParams = { | ||
_id: cartId, | ||
anonymousAccessToken: cartToken | ||
}; | ||
|
||
mockContext.collections.Cart.findOne.mockReturnValueOnce(Promise.resolve(null)); | ||
|
||
const result = await anonymousCartByCartId(mockContext, { cartId, cartToken }); | ||
expect(result).toEqual(null); | ||
expect(mockContext.collections.Cart.findOne).not.toHaveBeenCalledWith(callingParams); | ||
}); |