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

API: Remove 'immer' dependency #196

Merged
merged 2 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- [API] Increased the stability of the event sourcing code by replacing the "immer" dependency with a custom implementation.

## [1.0.0-beta.7] - 2019-04-03

### Added
Expand Down
46 changes: 30 additions & 16 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"fastify-jwt": "^0.3.0",
"fastify-metrics": "^2.0.2",
"fastify-swagger": "^0.15.0",
"immer": "^2.1.3",
"joi": "^14.3.1",
"jsonwebtoken": "^8.5.0",
"lodash.clonedeep": "^4.5.0",
Expand Down
16 changes: 16 additions & 0 deletions api/src/http_errors/bad_request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Joi = require("joi");
import { VError } from "verror";

import { Ctx } from "../lib/ctx";

interface Info {
ctx: Ctx;
requestPath: string;
validationResult: Joi.ValidationError;
}

export class BadRequest extends VError {
constructor(info: Info) {
super({ name: "BadRequest", info }, `invalid request to ${info.requestPath}`);
}
}
31 changes: 17 additions & 14 deletions api/src/service/cache2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import * as isEmpty from "lodash.isempty";

import { Ctx } from "../lib/ctx";
import * as Result from "../result";
import { Cache2, initCache, updateAggregates, getCacheInstance } from "./cache2";
import * as ProjectCreated from "../service/domain/workflow/project_created";
import * as ProjectClosed from "../service/domain/workflow/project_closed";
import * as ProjectAssigned from "../service/domain/workflow/project_assigned";
import * as SubprojectCreated from "../service/domain/workflow/subproject_created";
import * as ProjectClosed from "../service/domain/workflow/project_closed";
import * as ProjectCreated from "../service/domain/workflow/project_created";
import * as SubprojectAssigned from "../service/domain/workflow/subproject_assigned";
import * as SubprojectClosed from "../service/domain/workflow/subproject_closed";
import * as WorkflowitemCreated from "../service/domain/workflow/workflowitem_created";
import * as SubprojectCreated from "../service/domain/workflow/subproject_created";
import * as WorkflowitemAssigned from "../service/domain/workflow/workflowitem_assigned";
import * as WorkflowitemClosed from "../service/domain/workflow/workflowitem_closed";

import { BusinessEvent } from "./domain/business_event";
import * as WorkflowitemCreated from "../service/domain/workflow/workflowitem_created";
import { Cache2, getCacheInstance, initCache, updateAggregates } from "./cache2";
import { NotFound } from "./domain/errors/not_found";

describe("The cache updates", () => {
Expand Down Expand Up @@ -138,19 +136,22 @@ describe("The cache updates", () => {

// Check if lookup for the first project is correct
const lookUpForFirstProject = lookUp.get("p-id0");
if (!lookUpForFirstProject)
if (!lookUpForFirstProject) {
return assert.fail(undefined, undefined, "Lookup for first project not found");
}
assert.isFalse(isEmpty(lookUpForFirstProject));
assert.hasAllKeys(lookUpForFirstProject, ["s-id0", "s-id2", "s-id4"]);

// Check if lookup for the second project is correct
const lookUpForSecondProject = lookUp.get("p-id1");
if (!lookUpForSecondProject)
if (!lookUpForSecondProject) {
return assert.fail(undefined, undefined, "Lookup for second project not found");
}
assert.isFalse(isEmpty(lookUpForSecondProject));
assert.hasAllKeys(lookUpForSecondProject, ["s-id1", "s-id3"]);
});
});

context("workflowitem aggregates", async () => {
const defaultCtx: Ctx = {
requestId: "",
Expand Down Expand Up @@ -181,15 +182,15 @@ describe("The cache updates", () => {

// Apply events to existing cache
const testAssignee = "shiba";
const wfAssginedEvent = WorkflowitemAssigned.createEvent(
const wfAssignedEvent = WorkflowitemAssigned.createEvent(
"http",
"test",
projectId,
subprojectId,
workflowitemId,
testAssignee,
);
if (Result.isErr(wfAssginedEvent)) {
if (Result.isErr(wfAssignedEvent)) {
return assert.fail(undefined, undefined, "Workflowitem assigned event failed");
}
const wfCloseEvent = WorkflowitemClosed.createEvent(
Expand All @@ -202,7 +203,7 @@ describe("The cache updates", () => {
if (Result.isErr(wfCloseEvent)) {
return assert.fail(undefined, undefined, "Workflowitem closed event failed");
}
updateAggregates(defaultCtx, cache, [wfAssginedEvent, wfCloseEvent]);
updateAggregates(defaultCtx, cache, [wfAssignedEvent, wfCloseEvent]);

// Test if events have been reflected on the aggregate
const wfUnderTest = cache.cachedWorkflowItems.get(workflowitemId);
Expand Down Expand Up @@ -237,15 +238,17 @@ describe("The cache updates", () => {

// Check if lookup for the first subproject is correct
const lookUpForFirstSubproject = lookUp.get("s-id0");
if (!lookUpForFirstSubproject)
if (!lookUpForFirstSubproject) {
return assert.fail(undefined, undefined, "Lookup for first Subproject not found");
}
assert.isFalse(isEmpty(lookUpForFirstSubproject));
assert.hasAllKeys(lookUpForFirstSubproject, ["w-id0", "w-id2", "w-id4"]);

// Check if lookup for the second subproject is correct
const lookUpForSecondSubproject = lookUp.get("s-id1");
if (!lookUpForSecondSubproject)
if (!lookUpForSecondSubproject) {
return assert.fail(undefined, undefined, "Lookup for second Subproject not found");
}
assert.isFalse(isEmpty(lookUpForSecondSubproject));
assert.hasAllKeys(lookUpForSecondSubproject, ["w-id1", "w-id3"]);
});
Expand Down
Loading