Skip to content

Commit

Permalink
fix(all): in-memory not overriding http client (#3052)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed Sep 17, 2024
1 parent caead1a commit 57d215b
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 36 deletions.
17 changes: 14 additions & 3 deletions apps/demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import {
provideHttpClient,
withInterceptorsFromDi,
} from '@angular/common/http';
import { NgModule } from '@angular/core';
import {
importProvidersFrom,
NgModule,
} from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { EffectsModule } from '@ngrx/effects';
Expand Down Expand Up @@ -37,8 +40,6 @@ import { environment } from '../environments/environment';
BrowserModule,
BrowserAnimationsModule,

DemoDriverModule,

StoreModule.forRoot({}),
EffectsModule.forRoot([]),

Expand Down Expand Up @@ -72,7 +73,17 @@ import { environment } from '../environments/environment';
},
),
provideRouterStore(),
// network providers
provideHttpClient(withInterceptorsFromDi()),
// this must be after http client! ^
// this is mostly relevant for the in memory backend
// it seems that the way Angular loads providers
// means that the full provider tree will be loaded before
// importing modules. therefore, the in memory web API
// will not be able override the HTTP client backend
// when imported as a module
importProvidersFrom(DemoDriverModule),
//
],
bootstrap: [AppComponent],
})
Expand Down
48 changes: 27 additions & 21 deletions apps/design-land/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,31 @@ import { DesignLandAppComponent } from './app.component';
import { DesignLandNavModule } from './core/nav/nav.module';
import { DesignLandTemplateModule } from './core/template/template.module';

@NgModule({ declarations: [
DesignLandAppComponent,
],
bootstrap: [
DesignLandAppComponent,
], imports: [BrowserModule,
BrowserAnimationsModule,
DesignLandAppRoutingModule,
DaffSidebarModule,
DaffLinkSetModule,
DaffArticleModule,
DaffThemeSwitchButtonModule,
DaffNavbarModule,
DaffButtonModule,
FontAwesomeModule,
DesignLandNavModule,
DesignLandTemplateModule,
DaffToastModule], providers: [
DAFF_THEME_INITIALIZER,
provideHttpClient(withInterceptorsFromDi()),
] })
@NgModule({
declarations: [
DesignLandAppComponent,
],
bootstrap: [
DesignLandAppComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
DesignLandAppRoutingModule,
DaffSidebarModule,
DaffLinkSetModule,
DaffArticleModule,
DaffThemeSwitchButtonModule,
DaffNavbarModule,
DaffButtonModule,
FontAwesomeModule,
DesignLandNavModule,
DesignLandTemplateModule,
DaffToastModule,
],
providers: [
DAFF_THEME_INITIALIZER,
provideHttpClient(withInterceptorsFromDi()),
],
})
export class AppModule { }
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
provideHttpClient,
withInterceptorsFromDi,
} from '@angular/common/http';
import { importProvidersFrom } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import {
HttpClientInMemoryWebApiModule,
Expand All @@ -19,7 +20,6 @@ import {
} from '@daffodil/auth';
import { DaffAccountRegistrationFactory } from '@daffodil/auth/testing';


import { DaffInMemoryBackendAuthService } from './auth.service';

describe('DaffAuthInMemoryBackend | Integration', () => {
Expand All @@ -32,8 +32,10 @@ describe('DaffAuthInMemoryBackend | Integration', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientInMemoryWebApiModule.forRoot(DaffInMemoryBackendAuthService)],
providers: [provideHttpClient(withInterceptorsFromDi())],
providers: [
provideHttpClient(withInterceptorsFromDi()),
importProvidersFrom(HttpClientInMemoryWebApiModule.forRoot(DaffInMemoryBackendAuthService, { delay: 0 })),
],
});

httpClient = TestBed.inject(HttpClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
provideHttpClient,
withInterceptorsFromDi,
} from '@angular/common/http';
import { importProvidersFrom } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';

Expand Down Expand Up @@ -49,9 +50,14 @@ describe('DaffInMemoryBackendCartRootService | Integration', () => {

beforeEach(done => {
TestBed.configureTestingModule({
imports: [HttpClientInMemoryWebApiModule.forRoot(DaffInMemoryBackendCartRootService, { delay: 0 }),
DaffProductTestingModule],
providers: [provideHttpClient(withInterceptorsFromDi())],
imports: [
DaffProductTestingModule,
],
providers: [
provideHttpClient(withInterceptorsFromDi()),
// this must be loaded after provideHttpClient!
importProvidersFrom(HttpClientInMemoryWebApiModule.forRoot(DaffInMemoryBackendCartRootService, { delay: 0 })),
],
});

httpClient = TestBed.inject(HttpClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
provideHttpClient,
withInterceptorsFromDi,
} from '@angular/common/http';
import { importProvidersFrom } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';

Expand All @@ -21,8 +22,10 @@ describe('DaffInMemoryBackendGeographyService | Integration', () => {

beforeEach(done => {
TestBed.configureTestingModule({
imports: [HttpClientInMemoryWebApiModule.forRoot(DaffInMemoryBackendGeographyService, { delay: 0 })],
providers: [provideHttpClient(withInterceptorsFromDi())],
providers: [
provideHttpClient(withInterceptorsFromDi()),
importProvidersFrom(HttpClientInMemoryWebApiModule.forRoot(DaffInMemoryBackendGeographyService, { delay: 0 })),
],
});

httpClient = TestBed.inject(HttpClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
provideHttpClient,
withInterceptorsFromDi,
} from '@angular/common/http';
import { importProvidersFrom } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';

Expand All @@ -24,8 +25,10 @@ describe('@daffodil/order/driver/in-memory | DaffInMemoryBackendOrderService | I

beforeEach(done => {
TestBed.configureTestingModule({
imports: [HttpClientInMemoryWebApiModule.forRoot(DaffInMemoryBackendOrderService, { delay: 0 })],
providers: [provideHttpClient(withInterceptorsFromDi())],
providers: [
provideHttpClient(withInterceptorsFromDi()),
importProvidersFrom(HttpClientInMemoryWebApiModule.forRoot(DaffInMemoryBackendOrderService, { delay: 0 })),
],
});

httpClient = TestBed.inject(HttpClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
provideHttpClient,
withInterceptorsFromDi,
} from '@angular/common/http';
import { importProvidersFrom } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';

Expand All @@ -21,8 +22,10 @@ describe('@daffodil/reviews/driver/in-memory | DaffReviewsInMemoryBackendService

beforeEach(done => {
TestBed.configureTestingModule({
imports: [HttpClientInMemoryWebApiModule.forRoot(DaffReviewsInMemoryBackendService, { delay: 0 })],
providers: [provideHttpClient(withInterceptorsFromDi())],
providers: [
provideHttpClient(withInterceptorsFromDi()),
importProvidersFrom(HttpClientInMemoryWebApiModule.forRoot(DaffReviewsInMemoryBackendService, { delay: 0 })),
],
});

httpClient = TestBed.inject(HttpClient);
Expand Down

0 comments on commit 57d215b

Please sign in to comment.