-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from danieleisenhardt/feature/ignore-properties
- Loading branch information
Showing
6 changed files
with
81 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Ignore, ignoreKey } from './Ignore'; | ||
|
||
describe('IgnoreDecorator', () => { | ||
it('should decorate properties', () => { | ||
class Band { | ||
id: string; | ||
foo: string; | ||
@Ignore() | ||
bar: string; | ||
} | ||
|
||
const band = new Band(); | ||
|
||
expect(Reflect.getMetadata(ignoreKey, band, 'foo')).toBe(undefined); | ||
expect(Reflect.getMetadata(ignoreKey, band, 'bar')).toBe(true); | ||
}); | ||
}); |
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,6 @@ | ||
import 'reflect-metadata'; | ||
export const ignoreKey = Symbol('Ignore'); | ||
|
||
export function Ignore() { | ||
return Reflect.metadata(ignoreKey, true); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './Collection'; | ||
export * from './CustomRepository'; | ||
export * from './SubCollection'; | ||
export * from './Ignore'; |
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,28 @@ | ||
import { Collection, getRepository, Ignore } from '../../src'; | ||
import { Band as BandEntity } from '../fixture'; | ||
import { getUniqueColName } from '../setup'; | ||
|
||
describe('Integration test: Ignore Properties', () => { | ||
@Collection(getUniqueColName('band-simple-repository')) | ||
class Band extends BandEntity { | ||
@Ignore() | ||
temporaryName: string; | ||
} | ||
|
||
test('should ignore properties decorated with Ignore()', async () => { | ||
const bandRepository = getRepository(Band); | ||
// Create a band | ||
const dt = new Band(); | ||
dt.id = 'dream-theater'; | ||
dt.name = 'DreamTheater'; | ||
dt.temporaryName = 'Drömteater'; | ||
|
||
await bandRepository.create(dt); | ||
|
||
// Read a band | ||
const foundBand = await bandRepository.findById(dt.id); | ||
expect(foundBand.id).toEqual(dt.id); | ||
expect(foundBand.name).toEqual(dt.name); | ||
expect(foundBand).not.toHaveProperty('temporaryName'); | ||
}); | ||
}); |