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 injectBase with expected default values #311

Merged
merged 1 commit into from
Jan 15, 2025
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/neat-candles-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inversifyjs/core": patch
---

Updated `injectBase` default values to be true
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,33 @@ describe(getExtendedConstructorArguments.name, () => {
type: class {},
};

baseTypeClassMetadataFixture = ClassMetadataFixtures.any;
typeMetadataFixture = ClassMetadataFixtures.any;
baseTypeClassMetadataFixture = {
...ClassMetadataFixtures.any,
constructorArguments: [
{
kind: ClassElementMetadataKind.unmanaged,
},
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'service-identifier-2',
},
],
};
typeMetadataFixture = {
...ClassMetadataFixtures.any,
constructorArguments: [
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'service-identifier-1',
},
],
};
});

describe('when called', () => {
Expand All @@ -33,7 +58,22 @@ describe(getExtendedConstructorArguments.name, () => {
});

it('should return expected metadata', () => {
expect(result).toBe(typeMetadataFixture.constructorArguments);
expect(result).toStrictEqual([
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'service-identifier-1',
},
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'service-identifier-2',
},
]);
});
});
});
Expand Down Expand Up @@ -109,4 +149,61 @@ describe(getExtendedConstructorArguments.name, () => {
});
});
});

describe('having options with extendConstructorArguments false', () => {
let optionsFixture: InjectFromOptions;
let baseTypeClassMetadataFixture: ClassMetadata;
let typeMetadataFixture: ClassMetadata;

beforeAll(() => {
optionsFixture = {
extendConstructorArguments: false,
type: class {},
};

baseTypeClassMetadataFixture = {
...ClassMetadataFixtures.any,
constructorArguments: [
{
kind: ClassElementMetadataKind.unmanaged,
},
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'service-identifier-2',
},
],
};
typeMetadataFixture = {
...ClassMetadataFixtures.any,
constructorArguments: [
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'service-identifier-1',
},
],
};
});

describe('when called', () => {
let result: unknown;

beforeAll(() => {
result = getExtendedConstructorArguments(
optionsFixture,
baseTypeClassMetadataFixture,
typeMetadataFixture,
);
});

it('should return expected metadata', () => {
expect(result).toBe(typeMetadataFixture.constructorArguments);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function getExtendedConstructorArguments(
typeMetadata: ClassMetadata,
): ClassElementMetadata[] {
const extendConstructorArguments: boolean =
options.extendConstructorArguments ?? false;
options.extendConstructorArguments ?? true;

let extendedConstructorArguments: ClassElementMetadata[];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,46 @@ describe(getExtendedProperties.name, () => {
type: class {},
};

baseTypeClassMetadataFixture = ClassMetadataFixtures.any;
typeMetadataFixture = ClassMetadataFixtures.any;
baseTypeClassMetadataFixture = {
...ClassMetadataFixtures.any,
properties: new Map([
[
'property-1',
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'base-service-identifier-1',
},
],
[
'property-2',
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'base-service-identifier-2',
},
],
]),
};
typeMetadataFixture = {
...ClassMetadataFixtures.any,
properties: new Map([
[
'property-1',
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'service-identifier-1',
},
],
]),
};
});

describe('when called', () => {
Expand All @@ -33,12 +71,35 @@ describe(getExtendedProperties.name, () => {
});

it('should return expected metadata', () => {
expect(result).toBe(typeMetadataFixture.properties);
expect(result).toStrictEqual(
new Map([
[
'property-1',
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'service-identifier-1',
},
],
[
'property-2',
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'base-service-identifier-2',
},
],
]),
);
});
});
});

describe('having options with extendProperties', () => {
describe('having options with extendProperties true', () => {
let optionsFixture: InjectFromOptions;
let baseTypeClassMetadataFixture: ClassMetadata;
let typeMetadataFixture: ClassMetadata;
Expand Down Expand Up @@ -130,4 +191,74 @@ describe(getExtendedProperties.name, () => {
});
});
});

describe('having options with extendProperties false', () => {
let optionsFixture: InjectFromOptions;
let baseTypeClassMetadataFixture: ClassMetadata;
let typeMetadataFixture: ClassMetadata;

beforeAll(() => {
optionsFixture = {
extendProperties: false,
type: class {},
};

baseTypeClassMetadataFixture = {
...ClassMetadataFixtures.any,
properties: new Map([
[
'property-1',
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'base-service-identifier-1',
},
],
[
'property-2',
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'base-service-identifier-2',
},
],
]),
};
typeMetadataFixture = {
...ClassMetadataFixtures.any,
properties: new Map([
[
'property-1',
{
kind: ClassElementMetadataKind.singleInjection,
name: undefined,
optional: false,
tags: new Map(),
value: 'service-identifier-1',
},
],
]),
};
});

describe('when called', () => {
let result: unknown;

beforeAll(() => {
result = getExtendedProperties(
optionsFixture,
baseTypeClassMetadataFixture,
typeMetadataFixture,
);
});

it('should return expected metadata', () => {
expect(result).toBe(typeMetadataFixture.properties);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function getExtendedProperties(
baseTypeClassMetadata: ClassMetadata,
typeMetadata: ClassMetadata,
): Map<string | symbol, ClassElementMetadata> {
const extendProperties: boolean = options.extendProperties ?? false;
const extendProperties: boolean = options.extendProperties ?? true;

let extendedProperties: Map<string | symbol, ClassElementMetadata>;

Expand Down
Loading