11import CustomRepository from './CustomRepository' ;
22import { expect } from 'chai' ;
33import { MetadataStorage , Initialize } from '../MetadataStorage' ;
4+ import { BaseFirestoreRepository } from '..' ;
45
56describe ( 'CustomRepositoryDecorator' , ( ) => {
67 const store = { metadataStorage : new MetadataStorage ( ) } ;
@@ -16,14 +17,51 @@ describe('CustomRepositoryDecorator', () => {
1617 }
1718
1819 @CustomRepository ( Entity )
19- class EntityRepo { }
20+ class EntityRepo extends BaseFirestoreRepository < Entity > { }
2021
2122 const repository = store . metadataStorage . repositories . get ( Entity ) ;
2223 expect ( store . metadataStorage . repositories . size ) . to . eql ( 1 ) ;
2324 expect ( repository . entity ) . to . eql ( Entity ) ;
2425 expect ( repository . target ) . to . eql ( EntityRepo ) ;
2526 } ) ;
2627
27- it ( 'should enforce that custom repository inherits from BaseRepository' ) ;
28- it ( 'should only register a repository once' ) ;
28+ it ( 'should only register a repository once' , ( ) => {
29+ class Entity {
30+ id : string ;
31+ }
32+
33+ expect ( ( ) => {
34+ @CustomRepository ( Entity )
35+ class EntityRepo extends BaseFirestoreRepository < Entity > { }
36+
37+ @CustomRepository ( Entity )
38+ class EntityRepo2 extends BaseFirestoreRepository < Entity > { }
39+ } ) . to . throw ;
40+ } ) ;
41+
42+ it ( 'should only register a repository once' , ( ) => {
43+ class Entity {
44+ id : string ;
45+ }
46+
47+ @CustomRepository ( Entity )
48+ @CustomRepository ( Entity )
49+ class EntityRepo extends BaseFirestoreRepository < Entity > { }
50+
51+ const repository = store . metadataStorage . repositories . get ( Entity ) ;
52+ expect ( store . metadataStorage . repositories . size ) . to . eql ( 1 ) ;
53+ expect ( repository . entity ) . to . eql ( Entity ) ;
54+ expect ( repository . target ) . to . eql ( EntityRepo ) ;
55+ } ) ;
56+
57+ it ( 'should enforce that custom repository inherits from BaseRepository' , ( ) => {
58+ class Entity {
59+ id : string ;
60+ }
61+
62+ expect ( ( ) => {
63+ @CustomRepository ( Entity )
64+ class EntityRepo { }
65+ } ) . to . throw ;
66+ } ) ;
2967} ) ;
0 commit comments