-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do nto allow duplications in inherited type maps
- Loading branch information
Showing
6 changed files
with
61 additions
and
17 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
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
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
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
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,45 @@ | ||
import { MapperConfiguration, MappingPair } from '../../src'; | ||
|
||
describe('Transform duplication on inheritance', () => { | ||
class Entity { | ||
name: string; | ||
} | ||
|
||
class FooEntity extends Entity { | ||
} | ||
|
||
class BarEntity extends Entity { | ||
} | ||
|
||
class Dto { | ||
name: string; | ||
} | ||
|
||
class FooDto extends Dto {} | ||
|
||
class BarDto extends Dto {} | ||
|
||
const EntityToDto = new MappingPair(Entity, Dto); | ||
const FooEntityToDto = new MappingPair(FooEntity, FooDto); | ||
const BarEntityToDto = new MappingPair(BarEntity, BarDto); | ||
|
||
const mapper = new MapperConfiguration(cfg => { | ||
cfg.createAutoMap(EntityToDto, { | ||
name: opt => opt.addTransform(d => d + ', transformed!'), | ||
}) | ||
.include(FooEntityToDto) | ||
.include(BarEntityToDto); | ||
|
||
cfg.createAutoMap(FooEntityToDto, {}); | ||
|
||
cfg.createAutoMap(BarEntityToDto, {}); | ||
}).createMapper(); | ||
|
||
it('should map FooDto from base mapping pair', () => { | ||
const source = new FooEntity(); | ||
source.name = 'John'; | ||
|
||
const destination = mapper.map(FooEntityToDto, source) as FooDto; | ||
expect(destination.name).toBe('John, transformed!'); | ||
}); | ||
}); |
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