feat(medusa): cart context (#201)
- Adds a context field to Cart - context is automatically populated with ip + user agent - context can be updated via POST /store/cart/:id or set when creating via POST /store/cart
This commit is contained in:
@@ -72,6 +72,26 @@ describe("/store/carts", () => {
|
||||
const getRes = await api.post(`/store/carts/${response.data.cart.id}`);
|
||||
expect(getRes.status).toEqual(200);
|
||||
});
|
||||
|
||||
it("creates a cart with context", async () => {
|
||||
const api = useApi();
|
||||
const response = await api.post("/store/carts", {
|
||||
context: {
|
||||
test_id: "test",
|
||||
},
|
||||
});
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
const getRes = await api.post(`/store/carts/${response.data.cart.id}`);
|
||||
expect(getRes.status).toEqual(200);
|
||||
|
||||
const cart = getRes.data.cart;
|
||||
expect(cart.context).toEqual({
|
||||
ip: "::ffff:127.0.0.1",
|
||||
user_agent: "axios/0.21.1",
|
||||
test_id: "test",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /store/carts/:id", () => {
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
const glob = require(`glob`);
|
||||
|
||||
const pkgs = glob
|
||||
.sync(`${__dirname}/*/`)
|
||||
.map((p) => p.replace(__dirname, `<rootDir>/integration-tests`));
|
||||
// API
|
||||
|
||||
module.exports = {
|
||||
testEnvironment: `node`,
|
||||
rootDir: `../`,
|
||||
roots: pkgs,
|
||||
testPathIgnorePatterns: [
|
||||
`/examples/`,
|
||||
`/www/`,
|
||||
@@ -17,6 +11,6 @@ module.exports = {
|
||||
`__testfixtures__`,
|
||||
`.cache`,
|
||||
],
|
||||
transform: { "^.+\\.[jt]s$": `<rootDir>/jest-transformer.js` },
|
||||
setupFilesAfterEnv: ["<rootDir>/integration-tests/setup.js"],
|
||||
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
|
||||
setupFilesAfterEnv: ["../setup.js"],
|
||||
};
|
||||
|
||||
@@ -4,17 +4,19 @@
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "jest --runInBand",
|
||||
"build": "babel src -d dist --extensions \".ts,.js\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/medusa": "^1.1.3",
|
||||
"medusa-interfaces": "^1.1.0",
|
||||
"@medusajs/medusa": "1.1.11-dev-1615544779907",
|
||||
"medusa-interfaces": "1.1.1-dev-1615544779907",
|
||||
"typeorm": "^0.2.31"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.12.10",
|
||||
"@babel/core": "^7.12.10",
|
||||
"@babel/node": "^7.12.10",
|
||||
"babel-preset-medusa-package": "^1.1.0"
|
||||
"babel-preset-medusa-package": "1.1.0-dev-1615544779907",
|
||||
"jest": "^26.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,14 @@
|
||||
const path = require("path");
|
||||
const express = require("express");
|
||||
const getPort = require("get-port");
|
||||
|
||||
const loaders = require("@medusajs/medusa/dist/loaders").default;
|
||||
const importFrom = require("import-from");
|
||||
|
||||
const initialize = async () => {
|
||||
const app = express();
|
||||
|
||||
const loaders = importFrom(process.cwd(), "@medusajs/medusa/dist/loaders")
|
||||
.default;
|
||||
|
||||
const { dbConnection } = await loaders({
|
||||
directory: path.resolve(process.cwd()),
|
||||
expressApp: app,
|
||||
|
||||
Reference in New Issue
Block a user