CircleCI project setup (#138)

This commit is contained in:
Sebastian Rindom authored and GitHub committed 2020-11-21 15:50:42 +01:00
1 parent f5ec1b1b4c
commit c6996dd530
33 files changed
+3091 -432

No files matched your search

@@ -0,0 +1 @@
yarn.lock
@@ -0,0 +1,37 @@
# Logs
logs
*.log
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
*.un~
yarn.lock
src
flow-typed
coverage
decls
examples
# tests
__tests__
@@ -0,0 +1,26 @@
const r = require(`./resolver`);
function preset(context, options = {}) {
const { debug = false, nodeVersion = `10.14.0` } = options;
const { NODE_ENV, BABEL_ENV } = process.env;
const nodeConfig = {
corejs: 3,
useBuiltIns: `entry`,
targets: {
node: nodeVersion,
},
};
return {
presets: [r(`@babel/preset-env`)],
plugins: [
r(`@babel/plugin-proposal-class-properties`),
r(`@babel/plugin-transform-classes`),
r(`@babel/plugin-transform-instanceof`),
r(`@babel/plugin-transform-runtime`),
].filter(Boolean),
};
}
module.exports = preset;
@@ -0,0 +1,27 @@
{
"name": "babel-preset-medusa-package",
"version": "1.0.0",
"author": "Sebastian Rindom <sebastian@mrbltech.com>",
"repository": {
"type": "git",
"url": "https://github.com/medusajs/medusa.git",
"directory": "packages/babel-preset-medusa-package"
},
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-proposal-optional-chaining": "^7.12.1",
"@babel/plugin-transform-classes": "^7.12.1",
"@babel/plugin-transform-instanceof": "^7.12.1",
"@babel/plugin-transform-runtime": "^7.12.1",
"@babel/preset-env": "^7.12.7",
"core-js": "^3.7.0"
},
"peerDependencies": {
"@babel/core": "^7.11.6"
},
"license": "MIT",
"main": "index.js",
"engines": {
"node": ">=10.14.0"
}
}
@@ -0,0 +1,3 @@
const r = m => require.resolve(m)
module.exports = r;
+1
View File
@@ -15,6 +15,7 @@
"access": "public"
},
"scripts": {
"test": "jest",
"build": "babel src --out-dir dist/ --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir dist/ --ignore **/__tests__"
+1
View File
@@ -9,6 +9,7 @@
"directory": "packages/medusa-core-utils"
},
"scripts": {
"test": "jest",
"build": "babel src --out-dir dist/ --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir dist/ --ignore **/__tests__"
@@ -23,6 +23,7 @@
"jest": "^25.5.2"
},
"scripts": {
"test": "jest",
"build": "babel src -d .",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
@@ -23,6 +23,7 @@
"jest": "^25.5.2"
},
"scripts": {
"test": "jest",
"build": "babel src -d .",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
+1 -1
View File
@@ -26,7 +26,7 @@
"jest": "^25.5.2"
},
"scripts": {
"build": "babel src -d .",
"build": "babel src -d . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__",
"test": "jest"
@@ -2,6 +2,7 @@ export const TotalsServiceMock = {
getTotal: jest.fn(),
getTaxTotal: jest.fn(),
getAllocationItemDiscounts: jest.fn(),
getDiscountTotal: jest.fn(),
}
const mock = jest.fn().mockImplementation(() => {
@@ -10,7 +10,6 @@ describe("KlarnaProviderService", () => {
})
describe("createPayment", () => {
let result
const klarnaProviderService = new KlarnaProviderService(
{
totalsService: TotalsServiceMock,
@@ -28,19 +27,22 @@ describe("KlarnaProviderService", () => {
}
)
beforeEach(async () => {
beforeEach(() => {
jest.clearAllMocks()
})
it("creates Klarna order", async () => {
mockAxios.post.mockImplementation(() => {
mockAxios.post = jest.fn().mockImplementation(() => {
return Promise.resolve({
order_id: "123456789",
order_amount: 100,
data: {
order_id: "123456789",
order_amount: 100,
},
})
})
result = await klarnaProviderService.createPayment(carts.frCart)
const result = await klarnaProviderService.createPayment(carts.frCart)
expect(mockAxios.post).toHaveBeenCalledTimes(1)
expect(result).toEqual({
order_id: "123456789",
order_amount: 100,
@@ -68,7 +70,9 @@ describe("KlarnaProviderService", () => {
it("returns Klarna order", async () => {
mockAxios.get.mockImplementation((data) => {
return Promise.resolve({
order_id: "123456789",
data: {
order_id: "123456789",
},
})
})
@@ -133,19 +137,27 @@ describe("KlarnaProviderService", () => {
const klarnaProviderService = new KlarnaProviderService(
{
totalsService: TotalsServiceMock,
regionService: RegionServiceMock,
},
{
url: "medusajs/tests",
user: "lebronjames",
password: "123456789",
merchant_urls: {
terms: "terms",
checkout: "checkout",
confirmation: "confirmation",
},
}
)
it("returns updated Klarna order", async () => {
mockAxios.post.mockImplementation((data) => {
return Promise.resolve({
order_id: "123456789",
order_amount: 1000,
data: {
order_id: "123456789",
order_amount: 1000,
},
})
})
@@ -157,9 +169,7 @@ describe("KlarnaProviderService", () => {
},
},
},
{
order_amount: 1000,
}
carts.frCart
)
expect(result).toEqual({
@@ -191,7 +201,9 @@ describe("KlarnaProviderService", () => {
return Promise.resolve()
})
result = await klarnaProviderService.cancelPayment({ id: "123456789" })
result = await klarnaProviderService.cancelPayment({
order_id: "123456789",
})
expect(result).toEqual("123456789")
})
@@ -206,6 +218,7 @@ describe("KlarnaProviderService", () => {
const klarnaProviderService = new KlarnaProviderService(
{
totalsService: TotalsServiceMock,
regionService: RegionServiceMock,
},
{
url: "medusajs/tests",
@@ -234,6 +247,7 @@ describe("KlarnaProviderService", () => {
const klarnaProviderService = new KlarnaProviderService(
{
totalsService: TotalsServiceMock,
regionService: RegionServiceMock,
},
{
url: "medusajs/tests",
@@ -265,6 +279,7 @@ describe("KlarnaProviderService", () => {
const klarnaProviderService = new KlarnaProviderService(
{
totalsService: TotalsServiceMock,
regionService: RegionServiceMock,
},
{
url: "medusajs/tests",
@@ -276,7 +291,9 @@ describe("KlarnaProviderService", () => {
it("returns order id", async () => {
mockAxios.get.mockImplementation((data) => {
return Promise.resolve({
order: { order_amount: 1000 },
data: {
order: { order_amount: 1000 },
},
})
})
@@ -285,7 +302,7 @@ describe("KlarnaProviderService", () => {
})
result = await klarnaProviderService.capturePayment({
id: "123456789",
order_id: "123456789",
})
expect(result).toEqual("123456789")
@@ -301,6 +318,7 @@ describe("KlarnaProviderService", () => {
const klarnaProviderService = new KlarnaProviderService(
{
totalsService: TotalsServiceMock,
regionService: RegionServiceMock,
},
{
url: "medusajs/tests",
@@ -314,9 +332,9 @@ describe("KlarnaProviderService", () => {
return Promise.resolve()
})
result = await klarnaProviderService.capturePayment(
result = await klarnaProviderService.refundPayment(
{
id: "123456789",
order_id: "123456789",
},
1000
)
@@ -151,14 +151,14 @@ var carts = {
payment_sessions: [{
provider_id: "stripe",
data: {
id: "pi_123456789",
id: "pi_no",
customer: _medusaTestUtils.IdMap.getId("not-lebron")
}
}],
payment_method: {
provider_id: "stripe",
data: {
id: "pi_123456789",
id: "pi_no",
customer: _medusaTestUtils.IdMap.getId("not-lebron")
}
},
+3 -4
View File
@@ -16,6 +16,7 @@
"@babel/node": "^7.7.4",
"@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-transform-instanceof": "^7.8.3",
"@babel/plugin-transform-classes": "^7.9.5",
"@babel/plugin-transform-runtime": "^7.7.6",
"@babel/preset-env": "^7.7.5",
"@babel/register": "^7.7.4",
@@ -24,10 +25,10 @@
"cross-env": "^5.2.1",
"eslint": "^6.8.0",
"jest": "^25.5.2",
"medusa-test-utils": "^0.3.0"
"medusa-test-utils": "^1.0.11"
},
"scripts": {
"build": "babel src -d .",
"build": "babel src -d . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__",
"test": "jest"
@@ -36,11 +37,9 @@
"medusa-interfaces": "1.x"
},
"dependencies": {
"@babel/plugin-transform-classes": "^7.9.5",
"body-parser": "^1.19.0",
"express": "^4.17.1",
"medusa-core-utils": "^1.0.10",
"medusa-test-utils": "^1.0.11",
"stripe": "^8.50.0"
},
"gitHead": "3cc7cbe5124cbcbb75f6e1435db4dcfaa2a60408"
@@ -169,7 +169,7 @@ export const carts = {
{
provider_id: "stripe",
data: {
id: "pi_123456789",
id: "pi_no",
customer: IdMap.getId("not-lebron"),
},
},
@@ -177,7 +177,7 @@ export const carts = {
payment_method: {
provider_id: "stripe",
data: {
id: "pi_123456789",
id: "pi_no",
customer: IdMap.getId("not-lebron"),
},
},
@@ -1,14 +1,14 @@
import { IdMap } from "medusa-test-utils"
export const StripeProviderServiceMock = {
retrievePayment: jest.fn().mockImplementation((cart) => {
if (cart._id === IdMap.getId("fr-cart")) {
retrievePayment: jest.fn().mockImplementation((payData) => {
if (payData.id === "pi_123456789") {
return Promise.resolve({
id: "pi",
customer: "cus_123456789",
})
}
if (cart._id === IdMap.getId("fr-cart-no-customer")) {
if (payData.id === "pi_no") {
return Promise.resolve({
id: "pi",
})
@@ -4,6 +4,10 @@ import { CustomerServiceMock } from "../../__mocks__/customer"
import { carts } from "../../__mocks__/cart"
import { TotalsServiceMock } from "../../__mocks__/totals"
const RegionServiceMock = {
retrieve: jest.fn().mockReturnValue(Promise.resolve({})),
}
describe("StripeProviderService", () => {
describe("createCustomer", () => {
let result
@@ -12,6 +16,7 @@ describe("StripeProviderService", () => {
const stripeProviderService = new StripeProviderService(
{
customerService: CustomerServiceMock,
regionService: RegionServiceMock,
totalsService: TotalsServiceMock,
},
{
@@ -42,6 +47,7 @@ describe("StripeProviderService", () => {
const stripeProviderService = new StripeProviderService(
{
customerService: CustomerServiceMock,
regionService: RegionServiceMock,
totalsService: TotalsServiceMock,
},
{
@@ -80,6 +86,7 @@ describe("StripeProviderService", () => {
const stripeProviderService = new StripeProviderService(
{
customerService: CustomerServiceMock,
regionService: RegionServiceMock,
totalsService: TotalsServiceMock,
},
{
@@ -111,6 +118,7 @@ describe("StripeProviderService", () => {
const stripeProviderService = new StripeProviderService(
{
customerService: CustomerServiceMock,
regionService: RegionServiceMock,
totalsService: TotalsServiceMock,
},
{
@@ -144,6 +152,7 @@ describe("StripeProviderService", () => {
const stripeProviderService = new StripeProviderService(
{
customerService: CustomerServiceMock,
regionService: RegionServiceMock,
totalsService: TotalsServiceMock,
},
{
@@ -34,11 +34,14 @@ describe("CartSubscriber", () => {
expect(StripeProviderServiceMock.retrievePayment).toHaveBeenCalledTimes(1)
expect(StripeProviderServiceMock.retrievePayment).toHaveBeenCalledWith(
carts.frCart
carts.frCart.payment_sessions[0].data
)
expect(StripeProviderServiceMock.cancelPayment).toHaveBeenCalledTimes(1)
expect(StripeProviderServiceMock.cancelPayment).toHaveBeenCalledWith("pi")
expect(StripeProviderServiceMock.cancelPayment).toHaveBeenCalledWith({
id: "pi",
customer: "cus_123456789",
})
expect(StripeProviderServiceMock.createPayment).toHaveBeenCalledTimes(1)
expect(StripeProviderServiceMock.createPayment).toHaveBeenCalledWith(
@@ -66,7 +69,7 @@ describe("CartSubscriber", () => {
expect(StripeProviderServiceMock.retrievePayment).toHaveBeenCalledTimes(1)
expect(StripeProviderServiceMock.retrievePayment).toHaveBeenCalledWith(
carts.frCartNoStripeCustomer
carts.frCartNoStripeCustomer.payment_sessions[0].data
)
expect(StripeProviderServiceMock.createCustomer).toHaveBeenCalledTimes(1)
+1 -1
View File
@@ -28,7 +28,7 @@
"medusa-test-utils": "^1.0.11"
},
"scripts": {
"build": "babel src -d .",
"build": "babel src -d . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__",
"test": "jest"
@@ -30,6 +30,7 @@ describe("LineItemService", () => {
expect(result).toEqual({
title: "Product 1",
thumbnail: undefined,
should_merge: false,
content: {
unit_price: 50,
variant: {
@@ -62,6 +63,7 @@ describe("LineItemService", () => {
expect(result).toEqual({
title: "Product 1",
thumbnail: undefined,
should_merge: false,
content: {
unit_price: 150,
variant: {
@@ -31,7 +31,7 @@
"prettier": "^2.0.5"
},
"scripts": {
"build": "babel src -d .",
"build": "babel src -d . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__",
"test": "jest"
@@ -1,3 +1,5 @@
jest.unmock("axios")
import BrightpearlService from "../brightpearl"
import { mockCreateOrder } from "../../utils/brightpearl"
import MockAdapter from "axios-mock-adapter"
+1
View File
@@ -9,6 +9,7 @@
"directory": "packages/medusa-test-utils"
},
"scripts": {
"test": "jest",
"build": "babel src --out-dir dist/ --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir dist/ --ignore **/__tests__"
+1 -11
View File
@@ -7,16 +7,6 @@ if (process.env.NODE_ENV !== `test`) {
}
module.exports = {
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-classes",
"@babel/plugin-transform-instanceof",
],
presets: ["@babel/preset-env"],
env: {
test: {
plugins: ["@babel/plugin-transform-runtime"],
},
},
presets: [["babel-preset-medusa-package"]],
ignore,
}
+2 -1
View File
@@ -23,6 +23,7 @@
"@babel/preset-env": "^7.7.5",
"@babel/register": "^7.7.4",
"@babel/runtime": "^7.7.6",
"babel-preset-medusa-package": "^1.0.0",
"cross-env": "^5.2.1",
"eslint": "^6.8.0",
"jest": "^25.5.2",
@@ -34,7 +35,7 @@
"start": "nodemon --watch plugins/ --watch src/ --exec babel-node src/app.js",
"watch": "babel -w src --out-dir dist/ --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"build": "babel src -d dist",
"build": "babel src -d dist --ignore **/__tests__",
"serve": "node dist/app.js",
"test": "jest"
},
+4 -4
View File
@@ -4628,10 +4628,10 @@ medusa-core-utils@^1.0.10:
joi "^17.2.1"
joi-objectid "^3.0.1"
medusa-test-utils@^1.0.10:
version "1.0.10"
resolved "https://registry.yarnpkg.com/medusa-test-utils/-/medusa-test-utils-1.0.10.tgz#8c1e9046a81cd3afa4c32c6d0d8af7e1f33bd039"
integrity sha512-CTzlVVTEOIFh3iRsjJqt4JYtEFP+2gVZF0jXGYdhCgAxd5mFKVuE+QzLLtvTCHlT7TI7rYgPfEWCcj9LPh2vVQ==
medusa-test-utils@^1.0.11:
version "1.0.11"
resolved "https://registry.yarnpkg.com/medusa-test-utils/-/medusa-test-utils-1.0.11.tgz#bae901efa90426fb64818de700dc6e163820160f"
integrity sha512-CSNb70sXOfKTndzxWtPMYq+KeYaFkSLAPUyhuwDNVvkbne0faOYF5OMCV8r3aLoQ3D1Tvjrb/XB9Qt17ycjuPw==
dependencies:
"@babel/plugin-transform-classes" "^7.9.5"
medusa-core-utils "^1.0.10"