-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transport provider crud prepare rebased (#109)
* cherry pick new commits * service tests on top of reverted work
- Loading branch information
1 parent
eaea96c
commit cc14d5a
Showing
19 changed files
with
299 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
<p> | ||
configs works! | ||
</p> | ||
<router-outlet></router-outlet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
src/app/configs/transport-provider/transport-provider.component.ts
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
.../configs/transport-providers/tranport-providers-list/transport-provider-list.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Component, OnInit } from "@angular/core"; | ||
import { Observable } from "rxjs"; | ||
import { filter, first } from "rxjs/operators"; | ||
import { TransportProvider } from "src/app/online-orders/shared"; | ||
import { TransportProvidersService } from "src/app/online-orders/transport-providers.service"; | ||
|
||
@Component({ | ||
selector: "app-transport-list-provider", | ||
templateUrl: "./transport-provider-list.component.html", | ||
styleUrls: ["./transport-provider-list.component.css"], | ||
}) | ||
export class TransportProviderListComponent implements OnInit { | ||
public transportProviders$: Observable<TransportProvider[]>; | ||
public excludeCols: string[] = ["availabilityRules"]; | ||
|
||
constructor(private service: TransportProvidersService) {} | ||
|
||
handleRowSelect(selectedRecord: TransportProvider): void { | ||
// navigate to single record | ||
console.log(selectedRecord); | ||
} | ||
|
||
ngOnInit(): void { | ||
this.transportProviders$ = this.service.getTransportProviders(); | ||
|
||
// filter((x) => x.length !== 0 || !x) | ||
// first() | ||
} | ||
} |
Empty file.
1 change: 1 addition & 0 deletions
1
...figs/transport-providers/transport-providers-edit/transport-providers-edit.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>transport-providers-edit works!</p> |
24 changes: 24 additions & 0 deletions
24
...s/transport-providers/transport-providers-edit/transport-providers-edit.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
|
||
import { TransportProvidersEditComponent } from "./transport-providers-edit.component"; | ||
|
||
describe("TransportProvidersEditComponent", () => { | ||
let component: TransportProvidersEditComponent; | ||
let fixture: ComponentFixture<TransportProvidersEditComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [TransportProvidersEditComponent], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TransportProvidersEditComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("should create", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
...onfigs/transport-providers/transport-providers-edit/transport-providers-edit.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Component, OnInit } from "@angular/core"; | ||
|
||
@Component({ | ||
selector: "app-transport-providers-edit", | ||
templateUrl: "./transport-providers-edit.component.html", | ||
styleUrls: ["./transport-providers-edit.component.css"], | ||
}) | ||
export class TransportProvidersEditComponent {} |
28 changes: 28 additions & 0 deletions
28
src/app/configs/transport-providers/transport-providers-routing.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { NgModule } from "@angular/core"; | ||
import { RouterModule, Routes } from "@angular/router"; | ||
import { AuthGuardService } from "src/app/shared/services/auth-guard.service"; | ||
import { TransportProviderListComponent } from "./tranport-providers-list/transport-provider-list.component"; | ||
import { TransportProvidersEditComponent } from "./transport-providers-edit/transport-providers-edit.component"; | ||
|
||
const routes: Routes = [ | ||
{ | ||
path: "", | ||
redirectTo: "list", | ||
}, | ||
{ | ||
path: "list", | ||
component: TransportProviderListComponent, | ||
canActivate: [AuthGuardService], | ||
}, | ||
{ | ||
path: "edit:id", | ||
component: TransportProvidersEditComponent, | ||
canActivate: [AuthGuardService], | ||
}, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forChild(routes)], | ||
exports: [RouterModule], | ||
}) | ||
export class TransportProvidersRoutingModule {} |
15 changes: 15 additions & 0 deletions
15
src/app/configs/transport-providers/transport-providers.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NgModule } from "@angular/core"; | ||
import { CommonModule } from "@angular/common"; | ||
import { TransportProviderListComponent } from "./tranport-providers-list/transport-provider-list.component"; | ||
import { RecordsTableModule } from "src/app/shared/components/records-table/records-table.module"; | ||
import { TransportProvidersRoutingModule } from "./transport-providers-routing.module"; | ||
import { TransportProvidersEditComponent } from "./transport-providers-edit/transport-providers-edit.component"; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
TransportProviderListComponent, | ||
TransportProvidersEditComponent, | ||
], | ||
imports: [CommonModule, RecordsTableModule, TransportProvidersRoutingModule], | ||
}) | ||
export class TransportProvidersModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 115 additions & 13 deletions
128
src/app/online-orders/transport-providers.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,129 @@ | ||
import { TestBed, inject } from "@angular/core/testing"; | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
import { TestBed } from "@angular/core/testing"; | ||
|
||
import { TransportProvidersService } from "./transport-providers.service"; | ||
import { HttpClientModule } from "@angular/common/http"; | ||
import { HttpClient, HttpClientModule } from "@angular/common/http"; | ||
import { | ||
HttpClientTestingModule, | ||
HttpTestingController, | ||
} from "@angular/common/http/testing"; | ||
import { MessagesServiceSpy } from "../shared/testing/services.spy"; | ||
import { MessagesService } from "../shared/components/messages/messages.service"; | ||
import { TransportProvider } from "./shared"; | ||
import { of } from "rxjs"; | ||
|
||
describe("TransportProviderService", () => { | ||
let service: TransportProvidersService; | ||
let clientSpy: jasmine.SpyObj<HttpClient>; | ||
let messageSpy: jasmine.SpyObj<MessagesService>; | ||
let httpClientSpy: jasmine.SpyObj<HttpClient>; | ||
|
||
beforeEach(() => { | ||
httpClientSpy = jasmine.createSpyObj("HttpClient", ["get"]); | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
TransportProvidersService, | ||
{ | ||
provide: HttpClient, | ||
useValue: httpClientSpy, | ||
}, | ||
{ | ||
provide: MessagesService, | ||
useClass: MessagesServiceSpy, | ||
}, | ||
], | ||
imports: [], | ||
}); | ||
service = TestBed.inject(TransportProvidersService); | ||
httpClientSpy = TestBed.inject(HttpClient) as jasmine.SpyObj<HttpClient>; | ||
messageSpy = TestBed.inject( | ||
MessagesService | ||
) as jasmine.SpyObj<MessagesService>; | ||
}); | ||
|
||
it("should be created", () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
describe("chaching", () => { | ||
beforeEach(() => { | ||
spyOn(HttpClient.prototype, "get").calls.reset(); | ||
httpClientSpy.get.and.returnValue( | ||
of({ | ||
data: [new TransportProvider()], | ||
}) | ||
); | ||
}); | ||
|
||
it("when api called, session var is set", (done: DoneFn) => { | ||
service.getTransportProviders().subscribe(() => { | ||
expect( | ||
( | ||
JSON.parse( | ||
sessionStorage.getItem("tranportProviders") | ||
) as TransportProvider[] | ||
).length | ||
).toBe(1); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("when none, should callApi", (done: DoneFn) => { | ||
service.getTransportProviders().subscribe(() => { | ||
expect(httpClientSpy.get.calls.count()).toBe(1); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("when NOT stale, should not callApi", (done: DoneFn) => { | ||
service.providersAge = Date.now() - 300 * 999; // age logic is in service | ||
|
||
service.getTransportProviders().subscribe(() => { | ||
expect(httpClientSpy.get.calls.count()).toBe(0); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("TransportProviderServiceHttp", () => { | ||
let service: TransportProvidersService; | ||
let httpMock: HttpTestingController; | ||
let messageSpy: jasmine.SpyObj<MessagesService>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [TransportProvidersService], | ||
providers: [ | ||
{ | ||
provide: MessagesService, | ||
useClass: MessagesServiceSpy, | ||
}, | ||
], | ||
imports: [HttpClientModule, HttpClientTestingModule], | ||
}) | ||
.compileComponents() | ||
.catch((e) => console.error(e)); | ||
TestBed.inject(HttpTestingController); | ||
}); | ||
service = TestBed.inject(TransportProvidersService); | ||
httpMock = TestBed.inject(HttpTestingController); | ||
messageSpy = TestBed.inject( | ||
MessagesService | ||
) as jasmine.SpyObj<MessagesService>; | ||
}); | ||
|
||
it("should be created", inject( | ||
[TransportProvidersService], | ||
(service: TransportProvidersService) => { | ||
expect(service).toBeTruthy(); | ||
} | ||
)); | ||
describe("when http error", () => { | ||
it("should call showErrors toast", (done: DoneFn) => { | ||
service.getTransportProviders().subscribe({ | ||
next: () => done.fail("should have failed with the 500 error"), | ||
error: () => { | ||
expect(messageSpy.showErrors.calls.count()).toBe(1); | ||
done(); | ||
}, | ||
}); | ||
|
||
const testReq = httpMock.expectOne( | ||
"http://localhost:9876/api/transportproviders" | ||
); | ||
expect(testReq.request.method).toEqual("GET"); | ||
testReq.flush("", { status: 500, statusText: "SErver Error" }); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.