Skip to content

Commit

Permalink
feat(container): update BindWhenOnFluentSyntax with ancestor constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
notaphplover committed Jan 12, 2025
1 parent b84d2d8 commit df484d3
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-grapes-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inversifyjs/container": minor
---

Updated `BindWhenFluentSyntax` with `whenNoAncestorTagged`
5 changes: 5 additions & 0 deletions .changeset/polite-elephants-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inversifyjs/container": minor
---

Updated `BindWhenFluentSyntax` with `whenNoAncestorIs`
5 changes: 5 additions & 0 deletions .changeset/serious-kiwis-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inversifyjs/container": minor
---

Updated `BindWhenFluentSyntax` with `whenNoAncestorNamed`
5 changes: 5 additions & 0 deletions .changeset/wicked-singers-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inversifyjs/container": minor
---

Updated `BindWhenFluentSyntax` with `whenNoAncestor`
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ export interface BindWhenFluentSyntax<T> {
): BindOnFluentSyntax<T>;
whenDefault(): BindOnFluentSyntax<T>;
whenNamed(name: MetadataName): BindOnFluentSyntax<T>;
whenNoAncestor(
constraint: (metadata: BindingMetadata) => boolean,
): BindOnFluentSyntax<T>;
whenNoAncestorIs(serviceIdentifier: ServiceIdentifier): BindOnFluentSyntax<T>;
whenNoAncestorNamed(name: MetadataName): BindOnFluentSyntax<T>;
whenNoAncestorTagged(
tag: MetadataTag,
tagValue: unknown,
): BindOnFluentSyntax<T>;
whenNoParent(
constraint: (metadata: BindingMetadata) => boolean,
): BindOnFluentSyntax<T>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ jest.mock('../calculations/isAnyAncestorBindingMetadataWithServiceId');
jest.mock('../calculations/isAnyAncestorBindingMetadataWithTag');
jest.mock('../calculations/isBindingMetadataWithName');
jest.mock('../calculations/isBindingMetadataWithTag');
jest.mock('../calculations/isNoAncestorBindingMetadata');
jest.mock('../calculations/isNoAncestorBindingMetadataWithTag');
jest.mock('../calculations/isNoAncestorBindingMetadataWithServiceId');
jest.mock('../calculations/isNoAncestorBindingMetadataWithName');
jest.mock('../calculations/isNotParentBindingMetadata');
jest.mock('../calculations/isNotParentBindingMetadataWithName');
jest.mock('../calculations/isNotParentBindingMetadataWithServiceId');
Expand Down Expand Up @@ -52,6 +56,10 @@ import { isAnyAncestorBindingMetadataWithTag } from '../calculations/isAnyAncest
import { isBindingMetadataWithName } from '../calculations/isBindingMetadataWithName';
import { isBindingMetadataWithNoNameNorTags } from '../calculations/isBindingMetadataWithNoNameNorTags';
import { isBindingMetadataWithTag } from '../calculations/isBindingMetadataWithTag';
import { isNoAncestorBindingMetadata } from '../calculations/isNoAncestorBindingMetadata';
import { isNoAncestorBindingMetadataWithName } from '../calculations/isNoAncestorBindingMetadataWithName';
import { isNoAncestorBindingMetadataWithServiceId } from '../calculations/isNoAncestorBindingMetadataWithServiceId';
import { isNoAncestorBindingMetadataWithTag } from '../calculations/isNoAncestorBindingMetadataWithTag';
import { isNotParentBindingMetadata } from '../calculations/isNotParentBindingMetadata';
import { isNotParentBindingMetadataWithName } from '../calculations/isNotParentBindingMetadataWithName';
import { isNotParentBindingMetadataWithServiceId } from '../calculations/isNotParentBindingMetadataWithServiceId';
Expand Down Expand Up @@ -1176,6 +1184,123 @@ describe(BindWhenFluentSyntaxImplementation.name, () => {
expect(result).toBeInstanceOf(BindOnFluentSyntaxImplementation);
});
});

describe('.whenNoAncestor', () => {
let constraintFixture: (metadata: BindingMetadata) => boolean;

let result: unknown;

beforeAll(() => {
constraintFixture = () => true;

result =
bindWhenFluentSyntaxImplementation.whenNoAncestor(constraintFixture);
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call isNoAncestorBindingMetadata', () => {
expect(isNoAncestorBindingMetadata).toHaveBeenCalledTimes(1);
expect(isNoAncestorBindingMetadata).toHaveBeenCalledWith(
constraintFixture,
);
});

it('should return expected result', () => {
expect(result).toBeInstanceOf(BindOnFluentSyntaxImplementation);
});
});

describe('.whenNoAncestorIs', () => {
let serviceIdFixture: ServiceIdentifier;

let result: unknown;

beforeAll(() => {
serviceIdFixture = 'service-id-fixture';

result =
bindWhenFluentSyntaxImplementation.whenNoAncestorIs(serviceIdFixture);
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call isNoAncestorBindingMetadataWithServiceId', () => {
expect(isNoAncestorBindingMetadataWithServiceId).toHaveBeenCalledTimes(1);
expect(isNoAncestorBindingMetadataWithServiceId).toHaveBeenCalledWith(
serviceIdFixture,
);
});

it('should return expected result', () => {
expect(result).toBeInstanceOf(BindOnFluentSyntaxImplementation);
});
});

describe('.whenNoAncestorNamed', () => {
let nameFixture: MetadataName;

let result: unknown;

beforeAll(() => {
nameFixture = 'name-fixture';

result =
bindWhenFluentSyntaxImplementation.whenNoAncestorNamed(nameFixture);
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call isNoAncestorBindingMetadataWithName', () => {
expect(isNoAncestorBindingMetadataWithName).toHaveBeenCalledTimes(1);
expect(isNoAncestorBindingMetadataWithName).toHaveBeenCalledWith(
nameFixture,
);
});

it('should return expected result', () => {
expect(result).toBeInstanceOf(BindOnFluentSyntaxImplementation);
});
});

describe('.whenNoAncestorTagged', () => {
let tagFixture: MetadataTag;
let tagValueFixture: unknown;

let result: unknown;

beforeAll(() => {
tagFixture = 'tag-fixture';
tagValueFixture = Symbol();

result = bindWhenFluentSyntaxImplementation.whenNoAncestorTagged(
tagFixture,
tagValueFixture,
);
});

afterAll(() => {
jest.clearAllMocks();
});

it('should call isNoAncestorBindingMetadataWithTag', () => {
expect(isNoAncestorBindingMetadataWithTag).toHaveBeenCalledTimes(1);
expect(isNoAncestorBindingMetadataWithTag).toHaveBeenCalledWith(
tagFixture,
tagValueFixture,
);
});

it('should return expected result', () => {
expect(result).toBeInstanceOf(BindOnFluentSyntaxImplementation);
});
});
});

describe(BindWhenOnFluentSyntaxImplementation.name, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ import { isAnyAncestorBindingMetadataWithTag } from '../calculations/isAnyAncest
import { isBindingMetadataWithName } from '../calculations/isBindingMetadataWithName';
import { isBindingMetadataWithNoNameNorTags } from '../calculations/isBindingMetadataWithNoNameNorTags';
import { isBindingMetadataWithTag } from '../calculations/isBindingMetadataWithTag';
import { isNoAncestorBindingMetadata } from '../calculations/isNoAncestorBindingMetadata';
import { isNoAncestorBindingMetadataWithName } from '../calculations/isNoAncestorBindingMetadataWithName';
import { isNoAncestorBindingMetadataWithServiceId } from '../calculations/isNoAncestorBindingMetadataWithServiceId';
import { isNoAncestorBindingMetadataWithTag } from '../calculations/isNoAncestorBindingMetadataWithTag';
import { isNotParentBindingMetadata } from '../calculations/isNotParentBindingMetadata';
import { isNotParentBindingMetadataWithName } from '../calculations/isNotParentBindingMetadataWithName';
import { isNotParentBindingMetadataWithServiceId } from '../calculations/isNotParentBindingMetadataWithServiceId';
Expand Down Expand Up @@ -383,6 +387,31 @@ export class BindWhenFluentSyntaxImplementation<T>
): BindOnFluentSyntax<T> {
return this.when(isBindingMetadataWithTag(tag, tagValue));
}

public whenNoAncestor(
constraint: (metadata: BindingMetadata) => boolean,
): BindOnFluentSyntax<T> {
return this.when(isNoAncestorBindingMetadata(constraint));
}

public whenNoAncestorIs(
serviceIdentifier: ServiceIdentifier,
): BindOnFluentSyntax<T> {
return this.when(
isNoAncestorBindingMetadataWithServiceId(serviceIdentifier),
);
}

public whenNoAncestorNamed(name: MetadataName): BindOnFluentSyntax<T> {
return this.when(isNoAncestorBindingMetadataWithName(name));
}

public whenNoAncestorTagged(
tag: MetadataTag,
tagValue: unknown,
): BindOnFluentSyntax<T> {
return this.when(isNoAncestorBindingMetadataWithTag(tag, tagValue));
}
}

export class BindWhenOnFluentSyntaxImplementation<T>
Expand Down

0 comments on commit df484d3

Please sign in to comment.