Skip to content

Commit

Permalink
test(integration): extending entity class to avoid reusing it
Browse files Browse the repository at this point in the history
  • Loading branch information
wovalle committed Oct 19, 2019
1 parent 0dc257a commit 7c069f5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Decorators/SubCollection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ describe('SubCollectionDecorator', () => {
it('should register collections', () => {
class SubEntity {}
class Entity {
@SubCollection(SubEntity, 'subentities')
@SubCollection(SubEntity, 'subs')
readonly subentity: null;
}

expect(store.metadataStorage.subCollections.length).to.eql(1);
expect(store.metadataStorage.subCollections[0].name).to.eql('subentities');
expect(store.metadataStorage.subCollections[0].name).to.eql('subs');
expect(store.metadataStorage.subCollections[0].parentEntity).to.eql(Entity);
expect(store.metadataStorage.subCollections[0].entity).to.eql(SubEntity);
expect(store.metadataStorage.subCollections[0].propertyKey).to.eql(
Expand Down
11 changes: 10 additions & 1 deletion test/BandCollection.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { Collection, SubCollection } from '../src/Decorators';
import { Album, Coordinates } from './fixture';
import { Album as AlbumEntity, Coordinates } from './fixture';
import { ISubCollection } from '../src/types';
import { Type } from '../src';

// Why I do this? Because by using the instance of Album
// located in fixture.ts, you have the risk to reuse the
// same class in many tests and every method that depends
// in the instance of the class being unique might clash
// with each other (happened with GetRepository)
//
// Hours lost debugging this: 2
class Album extends AlbumEntity {}

@Collection('bands')
export class Band {
id: string;
Expand Down
10 changes: 8 additions & 2 deletions test/functional/3-subcollections.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Band, Album, getInitialData } from '../fixture';
import {
Band as BandEntity,
Album as AlbumEntity,
getInitialData,
} from '../fixture';
import {
GetRepository,
Collection,
Expand All @@ -9,8 +13,10 @@ import { getUniqueColName } from '../setup';
import { expect } from 'chai';

describe('Integration test: SubCollections', () => {
class Album extends AlbumEntity {}

@Collection(getUniqueColName('band-with-subcollections'))
class FullBand extends Band {
class FullBand extends BandEntity {
@SubCollection(Album)
albums: ISubCollection<Album>;
}
Expand Down

0 comments on commit 7c069f5

Please sign in to comment.