-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): add check to only run nest map on applicable identifiers i…
…n map member ISSUES CLOSED: #480
- Loading branch information
Showing
2 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
packages/integration-test/src/classes/issues/480/480.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { AutoMap, classes } from '@automapper/classes'; | ||
import { | ||
CamelCaseNamingConvention, | ||
createMap, | ||
createMapper, | ||
forMember, | ||
mapFrom, | ||
nullSubstitution, | ||
} from '@automapper/core'; | ||
|
||
enum Enum { | ||
Value1 = 'Value1', | ||
Value2 = 'Value2', | ||
} | ||
|
||
class Model { | ||
@AutoMap() | ||
data!: string; | ||
} | ||
|
||
class ModelDto { | ||
@AutoMap() | ||
dataDto!: string; | ||
} | ||
|
||
class Foo { | ||
@AutoMap(() => [String]) | ||
values!: Enum[]; | ||
@AutoMap(() => Model) | ||
model!: Model; | ||
@AutoMap(() => [Model]) | ||
models!: Model[]; | ||
} | ||
|
||
class Bar { | ||
@AutoMap(() => [String]) | ||
values!: Enum[]; | ||
@AutoMap(() => ModelDto) | ||
model!: ModelDto; | ||
@AutoMap(() => [ModelDto]) | ||
models!: ModelDto[]; | ||
} | ||
|
||
describe('Issue 480', () => { | ||
const mapper = createMapper({ | ||
strategyInitializer: classes(), | ||
namingConventions: new CamelCaseNamingConvention(), | ||
}); | ||
|
||
it('should map properly', () => { | ||
createMap( | ||
mapper, | ||
Model, | ||
ModelDto, | ||
forMember( | ||
(dto) => dto.dataDto, | ||
mapFrom((model) => model.data) | ||
) | ||
); | ||
createMap( | ||
mapper, | ||
Foo, | ||
Bar, | ||
forMember((bar) => bar.values, nullSubstitution([])), | ||
forMember((bar) => bar.model, nullSubstitution(new ModelDto())), | ||
forMember((bar) => bar.models, nullSubstitution([])) | ||
); | ||
|
||
const foo = new Foo(); | ||
foo.values = [Enum.Value1]; | ||
foo.model = new Model(); | ||
foo.model.data = 'data'; | ||
foo.models = [new Model()]; | ||
foo.models[0].data = 'data in array'; | ||
const bar = mapper.map(foo, Foo, Bar); | ||
expect(bar.values).toEqual([Enum.Value1]); | ||
expect(bar.model).toEqual({ dataDto: 'data' }); | ||
expect(bar.models).toEqual([{ dataDto: 'data in array' }]); | ||
}); | ||
}); |
unused; will remove