-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,80 @@ | ||
import { TestBed, async, inject } from '@angular/core/testing'; | ||
import { HttpModule } from '@angular/http'; | ||
import { AdminService } from './admin.service'; | ||
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { HttpRequest, HttpClientModule } from '@angular/common/http'; | ||
import { Admin } from '../model/admin'; | ||
|
||
let users = <Admin[]>[ | ||
{ | ||
resourceId: 'abc', | ||
role: 'SUPER_ADMIN', | ||
email: 'foo@bar.com', | ||
name: { | ||
first: 'Jane', | ||
last: 'Doe' | ||
} | ||
}, | ||
{ | ||
resourceId: 'def', | ||
role: 'DELEGATED_ADMIN', | ||
email: 'bar@baz.com', | ||
name: { | ||
first: 'John', | ||
last: 'Doe' | ||
} | ||
} | ||
]; | ||
|
||
describe('Admin Service', () => { | ||
let service: AdminService; | ||
// let service: AdminService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpModule], | ||
imports: [ | ||
HttpClientModule, | ||
HttpClientTestingModule | ||
], | ||
providers: [ | ||
AdminService | ||
] | ||
}); | ||
service = TestBed.get(AdminService); | ||
// service = TestBed.get(AdminService); | ||
}); | ||
|
||
it('should instantiate', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
describe('query', () => { | ||
it(`should send an expected query request`, async(inject([AdminService, HttpTestingController], | ||
(service: AdminService, backend: HttpTestingController) => { | ||
service.query().subscribe(); | ||
|
||
describe('query method', () => { | ||
it('should return a list of users', () => { | ||
expect(true).toBe(false); | ||
}); | ||
backend.expectOne((req: HttpRequest<any>) => { | ||
return req.url === '/api/users' | ||
&& req.method === 'GET'; | ||
}, `GET admin collection`); | ||
} | ||
))); | ||
}); | ||
describe('update method', () => { | ||
it('should send an http put request', () => { | ||
expect(true).toBe(false); | ||
}); | ||
it(`should send an expected put request`, async(inject([AdminService, HttpTestingController], | ||
(service: AdminService, backend: HttpTestingController) => { | ||
service.update({...users[0]}).subscribe(); | ||
|
||
backend.expectOne((req: HttpRequest<any>) => { | ||
return req.url === '/api/users/abc' | ||
&& req.method === 'PUT'; | ||
}, `PUT admin user`); | ||
} | ||
))); | ||
}); | ||
describe('remove method', () => { | ||
it('should send an http delete request', () => { | ||
expect(true).toBe(false); | ||
}); | ||
it(`should send an expected delete request`, async(inject([AdminService, HttpTestingController], | ||
(service: AdminService, backend: HttpTestingController) => { | ||
service.remove(users[0].resourceId).subscribe(); | ||
|
||
backend.expectOne((req: HttpRequest<any>) => { | ||
return req.url === '/api/users/abc' | ||
&& req.method === 'DELETE'; | ||
}, `DELETE admin user`); | ||
} | ||
))); | ||
}); | ||
}); |
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