Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove legacy #436

Merged
merged 25 commits into from
Sep 13, 2022
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0a9e2ca
fix: Use OpenAPI version 3.1. Nullable type as array was not supporte…
javierbrea Sep 7, 2022
a282188
feat: Remove core legacy
javierbrea Sep 8, 2022
fd973f6
test: Fix core E2E tests
javierbrea Sep 10, 2022
dbc442f
test: remove legacy core E2E tests
javierbrea Sep 10, 2022
e8f565b
chore: Build branch
javierbrea Sep 10, 2022
fda3ae0
feat: Support .cjs files
javierbrea Sep 10, 2022
2565c62
test: Fix api-client nodejs E2E tests
javierbrea Sep 11, 2022
d4fbc33
feat: Use alert id in adminAPI
javierbrea Sep 11, 2022
139ba2a
test: Fix cypress commands E2E tests
javierbrea Sep 11, 2022
69431cf
test: Fix main E2E tests
javierbrea Sep 11, 2022
64de1f2
test: Fix core E2E tests
javierbrea Sep 11, 2022
0d2afbd
test: Fix core E2E tests
javierbrea Sep 11, 2022
ee5f121
chore: Upgrade swagger
javierbrea Sep 11, 2022
f5da50f
test: Fix unit tests
javierbrea Sep 11, 2022
481e289
test: Fix tests
javierbrea Sep 11, 2022
7a036cf
test(unit): Fix unit tests
javierbrea Sep 11, 2022
85941c6
fix: Restore unit mock config
javierbrea Sep 11, 2022
83bb8bd
test: Fix unit tests
javierbrea Sep 12, 2022
e761737
test: migrate core functional tests from E2E to core unit tests
javierbrea Sep 12, 2022
885fe3e
test: Restore core coverage threshold
javierbrea Sep 12, 2022
0810ed3
docs: Add changes to changelogs
javierbrea Sep 13, 2022
a50cb5e
refactor: Removed unused vars
javierbrea Sep 13, 2022
afb8d4b
chore: Enable branch build
javierbrea Sep 13, 2022
cffc4b0
docs: Fix changelogs
javierbrea Sep 13, 2022
9ba18b3
chore: Fix Sonar smells
javierbrea Sep 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: Fix core E2E tests
  • Loading branch information
javierbrea committed Sep 10, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit fd973f627b203961c1666245be9125c16b493c3a
6 changes: 5 additions & 1 deletion packages/admin-api-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -9,7 +9,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
### Fixed
### Removed
### Breaking change

## [unreleased]

### Removed
- feat: Remove default client. BREAKING CHANGE

## [6.2.0] - 2022-08-11

1 change: 0 additions & 1 deletion packages/admin-api-client/README.md
Original file line number Diff line number Diff line change
@@ -131,7 +131,6 @@ apiClient.configClient({

## Release notes

* Due to backward compatibility reasons, the package also creates a default `AdminApiClient` automatically and exports all of its methods as functions available at first level. Usage of these "global" functions is discouraged, as they will be removed in next major version.
* Current major release is compatible only with `@mocks-server/main` versions upper or equal than `3.6`. Use prior releases for lower versions. If you don't want to update to the latest major version of this package yet but you want to update `@mocks-server/main`, you can also use any `5.x` version of this package with any `@mocks-server/main@3.x` version.

## Contributing
32 changes: 0 additions & 32 deletions packages/admin-api-client/src/methods.ts
Original file line number Diff line number Diff line change
@@ -71,35 +71,3 @@ export class AdminApiClient {
return this._adminApiClient.configClient(config);
}
}

const defaultClient = new AdminApiClient();

export const readAbout = defaultClient.readAbout.bind(defaultClient);

export const readConfig = defaultClient.readConfig.bind(defaultClient);

export const updateConfig = defaultClient.updateConfig.bind(defaultClient);

export const readAlerts = defaultClient.readAlerts.bind(defaultClient);

export const readAlert = defaultClient.readAlert.bind(defaultClient);

export const readCollections = defaultClient.readCollections.bind(defaultClient);

export const readCollection = defaultClient.readCollection.bind(defaultClient);

export const readRoutes = defaultClient.readRoutes.bind(defaultClient);

export const readRoute = defaultClient.readRoute.bind(defaultClient);

export const readVariants = defaultClient.readVariants.bind(defaultClient);

export const readVariant = defaultClient.readVariant.bind(defaultClient);

export const readCustomRouteVariants = defaultClient.readCustomRouteVariants.bind(defaultClient);

export const useRouteVariant = defaultClient.useRouteVariant.bind(defaultClient);

export const restoreRouteVariants = defaultClient.restoreRouteVariants.bind(defaultClient);

export const configClient = defaultClient.configClient.bind(defaultClient);
6 changes: 6 additions & 0 deletions packages/admin-api-paths/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
### Removed

## [unreleased]

### Removed
- feat: Remove legacy paths


## [4.2.0] - 2022-08-11

### Added
10 changes: 0 additions & 10 deletions packages/admin-api-paths/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
export const LEGACY_DEFAULT_BASE_PATH = "/admin";
export const LEGACY_SETTINGS = "/settings";
export const LEGACY_ABOUT = "/about";
export const LEGACY_ALERTS = "/alerts";

export const LEGACY_MOCKS = "/mocks";
export const LEGACY_ROUTES = "/routes";
export const LEGACY_ROUTES_VARIANTS = "/routes-variants";
export const LEGACY_MOCK_CUSTOM_ROUTES_VARIANTS = "/mock-custom-routes-variants";

export const BASE_PATH = "/api";
export const CONFIG = "/config";
export const ABOUT = "/about";
18 changes: 16 additions & 2 deletions packages/core/src/files/loaders/Collections.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ const { validateFileContent } = require("../helpers");

const ID = "collections";
const FILE_NAME = "collections";
const LEGACY_FILE_NAME = "mocks";

function findFile(filesContents, fileName) {
return filesContents.find((fileDetails) => {
@@ -12,14 +13,14 @@ function findFile(filesContents, fileName) {
}

function getFileToUse(filesContents) {
return findFile(filesContents, FILE_NAME);
return findFile(filesContents, FILE_NAME) || findFile(filesContents, LEGACY_FILE_NAME);
}

class CollectionsLoader {
constructor({ loadCollections, createLoader, getBasePath }) {
this._loader = createLoader({
id: ID,
src: [FILE_NAME],
src: [FILE_NAME, LEGACY_FILE_NAME],
onLoad: this._onLoad.bind(this),
});

@@ -44,6 +45,19 @@ class CollectionsLoader {
if (fileToUse) {
const filePath = fileToUse.path;
const fileContent = fileToUse.content;
const fileName = path.basename(filePath);
// LEGACY, to be removed
if (fileName.startsWith(LEGACY_FILE_NAME)) {
this._deprecationAlerts.set(
LEGACY_FILE_NAME,
`Defining collections in '${fileName}' file is deprecated. Please rename it to '${fileName.replace(
LEGACY_FILE_NAME,
FILE_NAME
)}'`
);
} else {
this._deprecationAlerts.remove(LEGACY_FILE_NAME);
}

try {
const fileErrors = validateFileContent(fileContent);
2 changes: 1 addition & 1 deletion packages/core/src/mock/Collection.js
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ class Collection {
this._router = express.Router();
this._routeVariants.forEach((routeVariant) => {
const logAndApplyDelay = (req, _res, next) => {
this._logger.info(`Request ${req.method} => ${req.url} | req: ${req.id}`);
routeVariant.logger.info(`Request ${req.method} => ${req.url} | req: ${req.id}`);
const delay = routeVariant.delay !== null ? routeVariant.delay : this._getDelay();
if (delay > 0) {
this._logger.verbose(`Applying delay of ${delay}ms to route variant '${this._id}'`);
2 changes: 2 additions & 0 deletions packages/core/src/mock/helpers.js
Original file line number Diff line number Diff line change
@@ -275,6 +275,7 @@ function getVariantHandler({

const variantNamespace = variantId || getVariantId(route.id, variantIndex);
const routeVariantLogger = loggerRoutes.namespace(variantNamespace);
loggerRoutes.debug(`Creating logger namespace for route variant ${variantNamespace}`);
const routeVariantAlerts = alertsRoutes.collection(variantNamespace);
const routeVariantCoreApi = new CoreApi({
core,
@@ -308,6 +309,7 @@ function getVariantHandler({
routeHandler.routeId = route.id;
routeHandler.url = route.url;
routeHandler.method = route.method;
routeHandler.logger = routeVariantLogger;
} catch (error) {
variantAlerts.set("process", error.message, error);
}
142 changes: 57 additions & 85 deletions packages/core/src/mock/validations.js
Original file line number Diff line number Diff line change
@@ -45,68 +45,24 @@ ajv.addKeyword({
});

const collectionsSchema = {
oneOf: [
{
type: "object",
properties: {
id: {
type: "string",
},
from: {
type: ["string", "null"],
},
routesVariants: {
type: "array",
uniqueItems: true,
items: {
type: "string",
},
},
},
required: ["id", "routesVariants"],
additionalProperties: false,
type: "object",
properties: {
id: {
type: "string",
},
{
type: "object",
properties: {
id: {
type: "string",
},
from: {
type: ["string", "null"],
},
routeVariants: {
type: "array",
uniqueItems: true,
items: {
type: "string",
},
},
},
required: ["id", "routeVariants"],
additionalProperties: false,
from: {
type: ["string", "null"],
},
{
type: "object",
properties: {
id: {
type: "string",
},
from: {
type: ["string", "null"],
},
routes: {
type: "array",
uniqueItems: true,
items: {
type: "string",
},
},
routes: {
type: "array",
uniqueItems: true,
items: {
type: "string",
},
required: ["id", "routes"],
additionalProperties: false,
},
],
},
required: ["id", "routes"],
additionalProperties: false,
};

const routesSchema = {
@@ -148,36 +104,52 @@ const routesSchema = {
variants: {
type: "array",
items: {
type: "object",
properties: {
id: {
type: "string",
},
disabled: {
type: "boolean",
},
handler: {
type: "string",
enum: [], // this enum is defined when validator is compiled
},
type: {
type: "string",
enum: [], // this enum is defined when validator is compiled
oneOf: [
{
type: "object",
properties: {
id: {
type: "string",
},
disabled: {
enum: [false],
},
type: {
type: "string",
enum: [], // this enum is defined when validator is compiled
},
delay: {
oneOf: [
{
type: "null",
},
{
type: "integer",
minimum: 0,
},
],
},
options: {
type: "object",
},
},
required: ["id", "type"],
additionalProperties: false,
},
delay: {
oneOf: [
{
type: "null",
{
type: "object",
properties: {
id: {
type: "string",
},
{
type: "integer",
minimum: 0,
disabled: {
enum: [true],
},
],
},
required: ["id", "disabled"],
additionalProperties: false,
},
},
// TODO, require "options" in all variants to be an object, do not allow additionalProperties. Deprecate "response"
required: ["id"],
],
},
},
},
@@ -210,7 +182,7 @@ function getIds(objs) {
function compileRouteValidator(variantHandlers) {
const supportedRouteHandlersIds = getIds(variantHandlers);
const schema = { ...routesSchema };
schema.properties.variants.items.properties.type.enum = supportedRouteHandlersIds;
schema.properties.variants.items.oneOf[0].properties.type.enum = supportedRouteHandlersIds;
routeSchema = { ...schema };
routeValidator = ajv.compile(schema);
}
4 changes: 2 additions & 2 deletions packages/core/src/plugins/Plugins.js
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ class Plugins {
coreApi;
const pluginOptions = { core: this._core, ...pluginMethods };
try {
// TODO, throw an error if plugin has no id
// TODO, throw an error if plugin has no id. legacy
if (Plugin.id) {
pluginConfig = this._config.addNamespace(Plugin.id);
pluginAlerts = this._alerts.collection(Plugin.id);
@@ -175,7 +175,7 @@ class Plugins {
}
this._pluginsOptions.push(coreApi);
}
// TODO, deprecate register method. It is duplicated with the constructor
// TODO, deprecate register method. It is duplicated with the constructor. Legacy
if (isFunction(pluginInstance.register)) {
try {
// TODO, if there is a problem registering, remove it
2 changes: 1 addition & 1 deletion packages/core/src/scaffold/mocks/routes/common.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ module.exports = [
variants: [
{
id: "enabled", // variant id
handler: "middleware", // variant handler id
type: "middleware", // variant handler id
options: {
// Express middleware to execute
middleware: (_req, res, next, core) => {
2 changes: 1 addition & 1 deletion packages/core/src/server/middlewares.js
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ const logRequest =
const notFound =
({ logger }) =>
(req, _res, next) => {
logger.debug(`Sending Not found response | ${req.id}`);
logger.debug(`Sending Not found response | ${req.method} => ${req.url} | ${req.id}`);
next(Boom.notFound());
};

4 changes: 0 additions & 4 deletions packages/core/src/variant-handlers/handlers/File.js
Original file line number Diff line number Diff line change
@@ -21,10 +21,6 @@ class File {
return "file";
}

static get version() {
return "4";
}

static get validationSchema() {
return {
type: "object",
4 changes: 0 additions & 4 deletions packages/core/src/variant-handlers/handlers/Json.js
Original file line number Diff line number Diff line change
@@ -15,10 +15,6 @@ class Json {
return "json";
}

static get version() {
return "4";
}

static get validationSchema() {
return {
type: "object",
Loading