Skip to content

Commit

Permalink
test(dataService): pass in actual values to mock service
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-small committed Dec 2, 2024
1 parent f76144c commit c22557b
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions libs/ngrx-toolkit/src/lib/with-data-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,7 @@ describe('withDataService', () => {

expect(store.entities().length).toBe(0);

store.create({
id: 3,
from: 'Wadena MN',
to: 'New York',
date: new Date().toDateString(),
delayed: false,
});
store.create(createFlight({id: 3, from: 'Wadena MN'}));
tick();
store.update(createFlight({id: 3}));
tick();
Expand All @@ -127,13 +121,7 @@ describe('withDataService', () => {

expect(store.flightEntities().length).toBe(0);

store.createFlight({
id: 3,
from: 'Wadena MN',
to: 'New York',
date: new Date().toDateString(),
delayed: false,
});
store.createFlight(createFlight({id: 3, from: 'Wadena MN'}));
tick();
store.updateFlight(createFlight({id: 3}));
tick();
Expand Down Expand Up @@ -284,7 +272,7 @@ describe('withDataService', () => {
});
});
}));
it('should the current entity', fakeAsync(() => {
it('should set the current entity', fakeAsync(() => {
TestBed.runInInjectionContext(() => {
const store = new Store();
tick();
Expand All @@ -296,7 +284,7 @@ describe('withDataService', () => {
expect(store.current()).toEqual(createFlight({id: 4}));
});
}));
it('set the current entity (with named collection)', fakeAsync(() => {
it('should set the current entity (with named collection)', fakeAsync(() => {
TestBed.runInInjectionContext(() => {
const store = new StoreWithNamedCollection();
tick();
Expand Down Expand Up @@ -439,7 +427,6 @@ class MockFlightService implements DataService<Flight, FlightFilter> {
}

create(entity: Flight): Promise<Flight> {
entity.id = 0;
return firstValueFrom(this.save(entity));
}

Expand All @@ -450,7 +437,7 @@ class MockFlightService implements DataService<Flight, FlightFilter> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
updateAll(entity: Flight[]): Promise<Flight[]> {
return firstValueFrom(
of([createFlight({id: 3}), createFlight({id: 4})])
of(entity)
);
}

Expand All @@ -467,11 +454,11 @@ class MockFlightService implements DataService<Flight, FlightFilter> {
}

private findById(id: string): Observable<Flight> {
return of(createFlight({id: 2}));
return of(createFlight({id: Number(id)}));
}

private save(flight: Flight): Observable<Flight> {
return of(createFlight({id: 3}));
return of(flight);
}

private remove(flight: Flight): Observable<void> {
Expand All @@ -488,7 +475,6 @@ class MockFlightServiceForLoading implements DataService<Flight, FlightFilter> {
}

create(entity: Flight): Promise<Flight> {
entity.id = 0;
return firstValueFrom(this.save(entity));
}

Expand All @@ -499,7 +485,7 @@ class MockFlightServiceForLoading implements DataService<Flight, FlightFilter> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
updateAll(entity: Flight[]): Promise<Flight[]> {
return firstValueFrom(
of([createFlight({id: 3}), createFlight({id: 4})]).pipe(delay(3))
of(entity).pipe(delay(3))
);
}

Expand All @@ -516,11 +502,11 @@ class MockFlightServiceForLoading implements DataService<Flight, FlightFilter> {
}

private findById(id: string): Observable<Flight> {
return of(createFlight({id: 2})).pipe(delay(3));
return of(createFlight({id: Number(id)})).pipe(delay(3));
}

private save(flight: Flight): Observable<Flight> {
return of(createFlight({id: 3})).pipe(delay(3));
return of(createFlight(flight)).pipe(delay(3));
}

private remove(flight: Flight): Observable<void> {
Expand Down

0 comments on commit c22557b

Please sign in to comment.