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

Update plan related error messages #314

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
5 changes: 5 additions & 0 deletions .changeset/fair-flies-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inversifyjs/core": minor
---

Updated plan related error messages with binding metadata details
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';

import { Binding } from '../../binding/models/Binding';
import { InternalBindingMetadata } from '../../binding/models/BindingMetadataImplementation';
import { BindingMetadata } from '../../binding/models/BindingMetadata';
import { bindingScopeValues } from '../../binding/models/BindingScope';
import { bindingTypeValues } from '../../binding/models/BindingType';
import { SingleInmutableLinkedList } from '../../common/models/SingleInmutableLinkedList';
import { BasePlanParams } from '../models/BasePlanParams';
import {
buildFilteredServiceBindings,
Expand All @@ -14,24 +13,18 @@ import {
describe(buildFilteredServiceBindings.name, () => {
describe('having no options', () => {
let paramsMock: jest.Mocked<BasePlanParams>;
let bindingMetadataListFixture: SingleInmutableLinkedList<InternalBindingMetadata>;
let bindingMetadataFixture: BindingMetadata;

beforeAll(() => {
paramsMock = {
getBindings: jest.fn(),
} as Partial<jest.Mocked<BasePlanParams>> as jest.Mocked<BasePlanParams>;
bindingMetadataListFixture = {
last: {
elem: {
name: 'name',
serviceIdentifier: 'service-id',
tags: new Map(),
},
previous: undefined,
},
} as Partial<
SingleInmutableLinkedList<InternalBindingMetadata>
> as SingleInmutableLinkedList<InternalBindingMetadata>;
bindingMetadataFixture = {
getAncestor: () => undefined,
name: 'name',
serviceIdentifier: 'service-id',
tags: new Map(),
};
});

describe('when called, and params.getBinding() returns undefined', () => {
Expand All @@ -40,7 +33,7 @@ describe(buildFilteredServiceBindings.name, () => {
beforeAll(() => {
result = buildFilteredServiceBindings(
paramsMock,
bindingMetadataListFixture,
bindingMetadataFixture,
);
});

Expand All @@ -51,7 +44,7 @@ describe(buildFilteredServiceBindings.name, () => {
it('should call params.getBinding()', () => {
expect(paramsMock.getBindings).toHaveBeenCalledTimes(1);
expect(paramsMock.getBindings).toHaveBeenCalledWith(
bindingMetadataListFixture.last.elem.serviceIdentifier,
bindingMetadataFixture.serviceIdentifier,
);
});

Expand Down Expand Up @@ -86,7 +79,7 @@ describe(buildFilteredServiceBindings.name, () => {

result = buildFilteredServiceBindings(
paramsMock,
bindingMetadataListFixture,
bindingMetadataFixture,
);
});

Expand All @@ -97,7 +90,7 @@ describe(buildFilteredServiceBindings.name, () => {
it('should call params.getBinding()', () => {
expect(paramsMock.getBindings).toHaveBeenCalledTimes(1);
expect(paramsMock.getBindings).toHaveBeenCalledWith(
bindingMetadataListFixture.last.elem.serviceIdentifier,
bindingMetadataFixture.serviceIdentifier,
);
});

Expand All @@ -109,25 +102,19 @@ describe(buildFilteredServiceBindings.name, () => {

describe('having options with customServiceIdentifier', () => {
let paramsMock: jest.Mocked<BasePlanParams>;
let bindingMetadataListFixture: SingleInmutableLinkedList<InternalBindingMetadata>;
let bindingMetadataFixture: BindingMetadata;
let optionsFixture: BuildFilteredServiceBindingsOptions;

beforeAll(() => {
paramsMock = {
getBindings: jest.fn(),
} as Partial<jest.Mocked<BasePlanParams>> as jest.Mocked<BasePlanParams>;
bindingMetadataListFixture = {
last: {
elem: {
name: 'name',
serviceIdentifier: 'service-id',
tags: new Map(),
},
previous: undefined,
},
} as Partial<
SingleInmutableLinkedList<InternalBindingMetadata>
> as SingleInmutableLinkedList<InternalBindingMetadata>;
bindingMetadataFixture = {
getAncestor: () => undefined,
name: 'name',
serviceIdentifier: 'service-id',
tags: new Map(),
};
optionsFixture = {
customServiceIdentifier: 'custom-service-id',
};
Expand All @@ -139,7 +126,7 @@ describe(buildFilteredServiceBindings.name, () => {
beforeAll(() => {
result = buildFilteredServiceBindings(
paramsMock,
bindingMetadataListFixture,
bindingMetadataFixture,
optionsFixture,
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { ServiceIdentifier } from '@inversifyjs/common';

import { Binding } from '../../binding/models/Binding';
import {
BindingMetadataImplementation,
InternalBindingMetadata,
} from '../../binding/models/BindingMetadataImplementation';
import { SingleInmutableLinkedList } from '../../common/models/SingleInmutableLinkedList';
import { BindingMetadata } from '../../binding/models/BindingMetadata';
import { BasePlanParams } from '../models/BasePlanParams';

export interface BuildFilteredServiceBindingsOptions {
Expand All @@ -14,12 +10,9 @@ export interface BuildFilteredServiceBindingsOptions {

export function buildFilteredServiceBindings(
params: BasePlanParams,
bindingMetadataList: SingleInmutableLinkedList<InternalBindingMetadata>,
bindingMetadata: BindingMetadata,
options?: BuildFilteredServiceBindingsOptions,
): Binding<unknown>[] {
const bindingMetadata: BindingMetadataImplementation =
new BindingMetadataImplementation(bindingMetadataList.last);

const serviceIdentifier: ServiceIdentifier =
options?.customServiceIdentifier ?? bindingMetadata.serviceIdentifier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals';
jest.mock('./isPlanServiceRedirectionBindingNode');
jest.mock('./throwErrorWhenUnexpectedBindingsAmountFound');

import { BindingMetadata } from '../../binding/models/BindingMetadata';
import { bindingScopeValues } from '../../binding/models/BindingScope';
import { bindingTypeValues } from '../../binding/models/BindingType';
import { ServiceRedirectionBinding } from '../../binding/models/ServiceRedirectionBinding';
import { MetadataTag } from '../../metadata/models/MetadataTag';
import { BindingNodeParent } from '../models/BindingNodeParent';
import { PlanServiceRedirectionBindingNode } from '../models/PlanServiceRedirectionBindingNode';
import { checkPlanServiceRedirectionBindingNodeSingleInjectionBindings } from './checkPlanServiceRedirectionBindingNodeSingleInjectionBindings';
Expand All @@ -18,6 +20,7 @@ describe(
describe('having a PlanServiceRedirectionBindingNode with no redirections', () => {
let planServiceRedirectionBindingNodeFixture: PlanServiceRedirectionBindingNode;
let isOptionalFixture: boolean;
let bindingMetadataFixture: BindingMetadata;

beforeAll(() => {
planServiceRedirectionBindingNodeFixture = {
Expand All @@ -27,6 +30,15 @@ describe(
redirections: [],
};
isOptionalFixture = false;
bindingMetadataFixture = {
getAncestor: () => undefined,
name: 'binding-name',
serviceIdentifier: 'service-identifier',
tags: new Map<MetadataTag, unknown>([
['tag1', 'value1'],
['tag2', 'value2'],
]),
};
});

describe('when called', () => {
Expand All @@ -37,6 +49,7 @@ describe(
checkPlanServiceRedirectionBindingNodeSingleInjectionBindings(
planServiceRedirectionBindingNodeFixture,
isOptionalFixture,
bindingMetadataFixture,
);
});

Expand All @@ -54,6 +67,7 @@ describe(
planServiceRedirectionBindingNodeFixture.redirections,
isOptionalFixture,
planServiceRedirectionBindingNodeFixture,
bindingMetadataFixture,
);
});

Expand All @@ -66,6 +80,7 @@ describe(
describe('having a PlanServiceRedirectionBindingNode with a single redirection to a leaf node', () => {
let planServiceRedirectionBindingNodeFixture: PlanServiceRedirectionBindingNode;
let isOptionalFixture: boolean;
let bindingMetadataFixture: BindingMetadata;

beforeAll(() => {
planServiceRedirectionBindingNodeFixture = {
Expand Down Expand Up @@ -94,6 +109,15 @@ describe(
],
};
isOptionalFixture = false;
bindingMetadataFixture = {
getAncestor: () => undefined,
name: 'binding-name',
serviceIdentifier: 'service-identifier',
tags: new Map<MetadataTag, unknown>([
['tag1', 'value1'],
['tag2', 'value2'],
]),
};
});

describe('when called, and isPlanServiceRedirectionBindingNode() returns false', () => {
Expand All @@ -110,6 +134,7 @@ describe(
checkPlanServiceRedirectionBindingNodeSingleInjectionBindings(
planServiceRedirectionBindingNodeFixture,
isOptionalFixture,
bindingMetadataFixture,
);
});

Expand All @@ -133,6 +158,7 @@ describe(
let planServiceRedirectionBindingNodeRedirectionFixture: PlanServiceRedirectionBindingNode;
let planServiceRedirectionBindingNodeFixture: PlanServiceRedirectionBindingNode;
let isOptionalFixture: boolean;
let bindingMetadataFixture: BindingMetadata;

beforeAll(() => {
planServiceRedirectionBindingNodeRedirectionFixture = {
Expand All @@ -148,6 +174,15 @@ describe(
redirections: [planServiceRedirectionBindingNodeRedirectionFixture],
};
isOptionalFixture = false;
bindingMetadataFixture = {
getAncestor: () => undefined,
name: 'binding-name',
serviceIdentifier: 'service-identifier',
tags: new Map<MetadataTag, unknown>([
['tag1', 'value1'],
['tag2', 'value2'],
]),
};
});

describe('when called, and isPlanServiceRedirectionBindingNode() returns true', () => {
Expand All @@ -164,6 +199,7 @@ describe(
checkPlanServiceRedirectionBindingNodeSingleInjectionBindings(
planServiceRedirectionBindingNodeFixture,
isOptionalFixture,
bindingMetadataFixture,
);
});

Expand All @@ -181,6 +217,7 @@ describe(
planServiceRedirectionBindingNodeRedirectionFixture.redirections,
isOptionalFixture,
planServiceRedirectionBindingNodeRedirectionFixture,
bindingMetadataFixture,
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BindingMetadata } from '../../binding/models/BindingMetadata';
import { PlanBindingNode } from '../models/PlanBindingNode';
import { PlanServiceRedirectionBindingNode } from '../models/PlanServiceRedirectionBindingNode';
import { isPlanServiceRedirectionBindingNode } from './isPlanServiceRedirectionBindingNode';
Expand All @@ -8,6 +9,7 @@ const SINGLE_INJECTION_BINDINGS: number = 1;
export function checkPlanServiceRedirectionBindingNodeSingleInjectionBindings(
serviceRedirectionBindingNode: PlanServiceRedirectionBindingNode,
isOptional: boolean,
bindingMetadata: BindingMetadata,
): void {
if (
serviceRedirectionBindingNode.redirections.length ===
Expand All @@ -20,6 +22,7 @@ export function checkPlanServiceRedirectionBindingNodeSingleInjectionBindings(
checkPlanServiceRedirectionBindingNodeSingleInjectionBindings(
planBindingNode,
isOptional,
bindingMetadata,
);
}

Expand All @@ -30,5 +33,6 @@ export function checkPlanServiceRedirectionBindingNodeSingleInjectionBindings(
serviceRedirectionBindingNode.redirections,
isOptional,
serviceRedirectionBindingNode,
bindingMetadata,
);
}
Loading
Loading