Creates test request helper for API endpoints

Separates common utils into the medusa-core-utils package.
Sets up a testing environment where mocked models/services/etc. can be placed in
__mocks__ folder within its corresponding directory. The mocks will
automatically be registered in a awilix container only used for testing.
This commit is contained in:
Sebastian Rindom
2020-01-21 15:13:47 +01:00
parent 3d494bc652
commit ed472e9fba
33 changed files with 14053 additions and 76 deletions
+9
View File
@@ -0,0 +1,9 @@
{
"plugins": ["@babel/plugin-proposal-class-properties"],
"presets": ["@babel/preset-env"],
"env": {
"test": {
"plugins": ["@babel/plugin-transform-runtime"]
}
}
}
+1
View File
@@ -0,0 +1 @@
dist/
+31
View File
@@ -0,0 +1,31 @@
{
"name": "medusa-core-utils",
"version": "1.0.0",
"description": "Core utils for Medusa",
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "https://github.com/srindom/medusa",
"directory": "packages/medusa-core-utils"
},
"scripts": {
"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__"
},
"author": "Sebastian Rindom",
"license": "AGPL-3.0-or-later",
"devDependencies": {
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5",
"@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-transform-runtime": "^7.7.6",
"@babel/preset-env": "^7.7.5",
"client-sessions": "^0.8.0",
"cross-env": "^5.2.1"
},
"dependencies": {
"@hapi/joi": "^16.1.8",
"joi-objectid": "^3.0.1"
}
}
+38
View File
@@ -0,0 +1,38 @@
/**
* @typedef MedusaErrorType
*
*/
export const MedusaErrorTypes = {
/** Errors stemming from the database */
DB_ERROR: "database_error",
INVALID_ARGUMENT: "invalid_argument",
INVALID_DATA: "invalid_data",
NOT_FOUND: "not_found"
}
/**
* Standardized error to be used across Medusa project.
* @extends Error
*/
class MedusaError extends Error {
/**
* Creates a standardized error to be used across Medusa project.
* @param type {MedusaErrorType} - the type of error.
* @param params {Array} - Error params.
*/
constructor(name, message, ...params) {
super(...params)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, MedusaError)
}
this.name = name
this.message = message
this.date = new Date()
}
}
MedusaError.Types = MedusaErrorTypes
export default MedusaError
+2
View File
@@ -0,0 +1,2 @@
export { default as Validator } from "./validator"
export { default as MedusaError } from "./errors"
@@ -0,0 +1,5 @@
import Joi from "@hapi/joi"
Joi.objectId = require("joi-objectid")(Joi)
export default Joi
File diff suppressed because it is too large Load Diff