-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add more inheritance tests - add support for custom discriminator properties - add ".idea" to gitignore - prop: add support for extended array items this is a squash merge of #21
- Loading branch information
Showing
8 changed files
with
108 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ crashlytics.properties | |
crashlytics-build.properties | ||
fabric.properties | ||
|
||
.idea | ||
### Linux ### | ||
*~ | ||
|
||
|
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,41 @@ | ||
import { arrayProp, prop } from '../../src/prop'; | ||
import { getModelForClass, modelOptions } from '../../src/typegoose'; | ||
|
||
@modelOptions({ | ||
schemaOptions: { | ||
discriminatorKey: 'width', | ||
collection: 'buildings' | ||
} | ||
}) | ||
export class Building { | ||
@prop({default: 100}) | ||
public width: number; | ||
} | ||
|
||
export class OfficeBuilding extends Building { | ||
@prop({default: 4}) | ||
public doors: number; | ||
} | ||
|
||
export class Garage extends Building { | ||
@prop({default: 10}) | ||
public slotsForCars: number; | ||
} | ||
|
||
@modelOptions({ | ||
schemaOptions: { | ||
collection: 'skyscrapers' | ||
} | ||
}) | ||
export class Skyscraper extends OfficeBuilding { | ||
@prop({default: 'Some cool string'}) | ||
public name: string; | ||
|
||
@prop() | ||
public mainGarage: Garage; | ||
|
||
@arrayProp({items: Garage}) | ||
public garagesInArea: Garage[]; | ||
} | ||
|
||
export const model = getModelForClass<Skyscraper, any >(Skyscraper); |
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,43 @@ | ||
import { expect } from 'chai'; | ||
import { model as inheritanceClass, Skyscraper } from '../models/inheritanceClass'; | ||
|
||
export function suite() { | ||
it('should set all direct parent props', async () => { | ||
const instance = await inheritanceClass.create({}); | ||
expect(instance.name).to.equals('Some cool string'); | ||
expect(instance.doors).to.equals(4); | ||
expect(instance.width).to.equals(100); | ||
}); | ||
|
||
it('should merge all parent schema options', async () => { | ||
const instance = await inheritanceClass.create({}); | ||
expect(instance.schema.get('collection')).to.equals('skyscrapers'); | ||
expect(instance.schema.get('discriminatorKey')).to.equals('width'); | ||
}); | ||
|
||
it('should set all parent props for nested schemas', async () => { | ||
const input = { | ||
mainGarage: { | ||
slotsForCars: 3 | ||
} | ||
} as Skyscraper; | ||
const instance = await inheritanceClass.create(input); | ||
expect(instance.mainGarage.slotsForCars).to.equals(3); | ||
expect(instance.mainGarage.width).to.equals(100); | ||
expect(instance.mainGarage.doors).to.equals(undefined); | ||
}); | ||
|
||
it('should set all parent props for nested array items', async () => { | ||
const input = { | ||
garagesInArea: [{ | ||
slotsForCars: 2 | ||
}] | ||
} as Skyscraper; | ||
const instance = await inheritanceClass.create(input); | ||
expect(instance.garagesInArea).to.be.lengthOf(1); | ||
const firstGarage = instance.garagesInArea.pop(); | ||
expect(firstGarage.slotsForCars).to.equals(2); | ||
expect(firstGarage.width).to.equals(100); | ||
expect(firstGarage.doors).to.be.equals(undefined); | ||
}); | ||
} |
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