Skip to content

Commit

Permalink
Merge pull request #7 from wovalle/fix/repository-array-contains-naming
Browse files Browse the repository at this point in the history
Fix: inconsistent array contains method naming
  • Loading branch information
wovalle authored Feb 6, 2019
2 parents 4beb406 + b629367 commit b30e0d3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/BaseFirestoreRepository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ describe('BaseRepository', () => {
entity.id = 'perfect-circle';
entity.name = 'A Perfect Circle';
entity.formationYear = 1999;
entity.genres = ['alternative-rock', 'alternative-metal', 'hard-rock']

entity.genres = ['alternative-rock', 'alternative-metal', 'hard-rock'];

const band = await bandRepository.create(entity);
expect(band.id).to.equal(entity.id);
Expand Down Expand Up @@ -95,7 +94,9 @@ describe('BaseRepository', () => {
});

it('must filter with whereEqualTo', async () => {
const list = await bandRepository.whereEqualTo('name', 'Porcupine Tree').find();
const list = await bandRepository
.whereEqualTo('name', 'Porcupine Tree')
.find();
expect(list.length).to.equal(1);
expect(list[0].name).to.equal('Porcupine Tree');
});
Expand All @@ -118,6 +119,7 @@ describe('BaseRepository', () => {
const list = await bandRepository
.whereLessThan('formationYear', 1983)
.find();

expect(list.length).to.equal(1);
});

Expand All @@ -128,16 +130,16 @@ describe('BaseRepository', () => {
expect(list.length).to.equal(2);
});

it('must filter with whereArrayCointain', async () => {
it('must filter with whereArrayContains', async () => {
const list = await bandRepository
.whereArrayCointain('genres', 'progressive-rock')
.whereArrayContains('genres', 'progressive-rock')
.find();
expect(list.length).to.equal(2);
});
it('must filter with two or more operators', async () => {
const list = await bandRepository
.whereLessOrEqualThan('formationYear', 1983)
.whereArrayCointain('genres', 'funk-rock')
.whereArrayContains('genres', 'funk-rock')
.find();
expect(list.length).to.equal(1);
expect(list[0].id).to.equal('red-hot-chili-peppers');
Expand All @@ -153,7 +155,7 @@ describe('BaseRepository', () => {

it('should be able to execute operations in the subcollection', async () => {
const band = await bandRepository.findById('red-hot-chili-peppers');
const bestAlbum = await band.albums.findById('stadium-arcadium')
const bestAlbum = await band.albums.findById('stadium-arcadium');
expect(bestAlbum.id).to.equal('stadium-arcadium');
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/BaseFirestoreRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ export default class BaseFirestoreRepository<T extends { id: string }>
);
}

whereArrayCointain(prop: keyof T, val: IFirestoreVal): QueryBuilder<T> {
return new QueryBuilder<T>(this.firestoreCollection).whereArrayCointain(
whereArrayContains(prop: keyof T, val: IFirestoreVal): QueryBuilder<T> {
return new QueryBuilder<T>(this.firestoreCollection).whereArrayContains(
prop,
val
);
Expand Down
2 changes: 1 addition & 1 deletion src/QueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class QueryBuilder<T extends { id: string }>
return this;
}

whereArrayCointain(prop: keyof T, val: IFirestoreVal): QueryBuilder<T> {
whereArrayContains(prop: keyof T, val: IFirestoreVal): QueryBuilder<T> {
this.queries.push({
prop: prop.toString(),
val,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface IQueryBuilder<T extends { id: string }> {
whereGreaterOrEqualThan(prop: keyof T, val: IFirestoreVal): IQueryBuilder<T>;
whereLessThan(prop: keyof T, val: IFirestoreVal): IQueryBuilder<T>;
whereLessOrEqualThan(prop: keyof T, val: IFirestoreVal): IQueryBuilder<T>;
whereArrayCointain(prop: keyof T, val: IFirestoreVal): IQueryBuilder<T>;
whereArrayContains(prop: keyof T, val: IFirestoreVal): IQueryBuilder<T>;
find(): Promise<T[]>;
}

Expand Down

0 comments on commit b30e0d3

Please sign in to comment.