Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
emilien.escalle committed Apr 10, 2019
1 parent c2aa647 commit b522bd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Typegoose', () => {
price: mongoose.Types.Decimal128.fromString('28189.25'),
}, {
model: 'Zastava',
price: mongoose.Types.Decimal128.fromString('1234.25'),
price: mongoose.Types.Decimal128.fromString('1234.25'),
}]);

const user = await User.create({
Expand All @@ -56,6 +56,7 @@ describe('Typegoose', () => {
title: 'Manager',
}],
previousCars: [trabant.id, zastava.id],
encodedKey: 'This an sample string',
});

{
Expand Down Expand Up @@ -89,6 +90,7 @@ describe('Typegoose', () => {

expect(foundUser).to.have.property('fullName', 'John Doe');

expect(foundUser).to.have.property('encodedKey', 'This an sample string');

const [janitor, manager] = foundUser.previousJobs;
expect(janitor).to.have.property('title', 'Janitor');
Expand Down Expand Up @@ -169,7 +171,7 @@ describe('Typegoose', () => {

expect(savedUser.languages).to.include('Hungarian');
expect(savedUser.previousJobs.length).to.be.above(0);
savedUser.previousJobs.map((prevJob) => {
savedUser.previousJobs.map((prevJob) => {
expect(prevJob.startedAt).to.be.ok;
});
});
Expand Down Expand Up @@ -288,7 +290,7 @@ describe('getClassForDocument()', () => {
it('Should validate email', async () => {
try {
await Person.create({
email: 'email',
email: 'email',
});
fail('Validation must fail.');
} catch (e) {
Expand Down
6 changes: 6 additions & 0 deletions src/test/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export class User extends Typegoose {
@arrayProp({ itemsRef: Car })
previousCars?: Ref<Car>[];

@prop({
set: (value) => value ? Buffer.from(value).toString('base64') : value,
get: (value: any) => value ? Buffer.from(value, 'base64').toString('ascii') : value,
})
encodedKey?: string;

@staticMethod
static findByAge(this: ModelType<User> & typeof User, age: number) {
return this.findOne({ age });
Expand Down

0 comments on commit b522bd1

Please sign in to comment.