1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-11-28 08:58:49 +02:00

fixing tests

This commit is contained in:
Braun Patrik 2017-07-03 19:39:09 +02:00
parent eaa3c15825
commit d07fa645c4
2 changed files with 25 additions and 23 deletions

View File

@ -1,14 +1,13 @@
import {inject, TestBed} from "@angular/core/testing";
import {UserService} from "./user.service";
import {UserDTO} from "../../../../common/entities/UserDTO";
import {Message} from "../../../../common/entities/Message";
import "rxjs/Rx";
import {LoginCredential} from "../../../../common/entities/LoginCredential";
import {AuthenticationService} from "./authentication.service";
class MockUserService {
public login(credential: LoginCredential) {
return Promise.resolve(new Message<UserDTO>(null, <UserDTO>{name: "testUserName"}))
public login(credential: LoginCredential): Promise<UserDTO> {
return Promise.resolve(<UserDTO>{name: "testUserName"})
}
public async getSessionUser() {
@ -34,20 +33,23 @@ describe('AuthenticationService', () => {
expect(userService.login).toHaveBeenCalled();
}));
it('should have NO Authenticated use', inject([AuthenticationService], (authService) => {
expect(authService.getUser()).toBe(null);
it('should have NO Authenticated use', inject([AuthenticationService], (authService: AuthenticationService) => {
expect(authService.user.value).toBe(null);
expect(authService.isAuthenticated()).toBe(false);
}));
it('should have Authenticated use', inject([AuthenticationService], (authService) => {
spyOn(authService.OnUserChanged, "trigger").and.callThrough();
authService.login();
authService.OnUserChanged.on(() => {
expect(authService.OnUserChanged.trigger).toHaveBeenCalled();
expect(authService.getUser()).not.toBe(null);
it('should have Authenticated use', inject([AuthenticationService], (authService: AuthenticationService) => {
spyOn(authService.user, "next").and.callThrough();
authService.user.subscribe((user) => {
if (user == null) {
return;
}
expect(authService.user.next).toHaveBeenCalled();
expect(authService.user.value).not.toBe(null);
expect(authService.isAuthenticated()).toBe(true);
});
authService.login(<any>{});
}));

View File

@ -53,37 +53,37 @@ describe('NetworkService Success tests', () => {
it('should call GET', inject([NetworkService], (networkService) => {
networkService.getJson(testUrl).then((res: Message<any>) => {
expect(res.result).toBe(testResponse);
networkService.getJson(testUrl).then((res: any) => {
expect(res).toBe(testResponse);
});
}));
it('should call POST', inject([NetworkService, MockBackend], (networkService) => {
networkService.postJson(testUrl, testData).then((res: Message<any>) => {
expect(res.result).toBe(testResponse);
networkService.postJson(testUrl, testData).then((res: any) => {
expect(res).toBe(testResponse);
});
expect(connection.request.text()).toBe(JSON.stringify(testData));
networkService.postJson(testUrl).then((res: Message<any>) => {
expect(res.result).toBe(testResponse);
networkService.postJson(testUrl).then((res: any) => {
expect(res).toBe(testResponse);
});
expect(connection.request.text()).toBe(JSON.stringify({}));
}));
it('should call PUT', inject([NetworkService, MockBackend], (networkService) => {
networkService.putJson(testUrl, testData).then((res: Message<any>) => {
expect(res.result).toBe(testResponse);
networkService.putJson(testUrl, testData).then((res: any) => {
expect(res).toBe(testResponse);
});
expect(connection.request.text()).toBe(JSON.stringify(testData));
networkService.putJson(testUrl).then((res: Message<any>) => {
expect(res.result).toBe(testResponse);
networkService.putJson(testUrl).then((res: any) => {
expect(res).toBe(testResponse);
});
expect(connection.request.text()).toBe(JSON.stringify({}));
@ -91,8 +91,8 @@ describe('NetworkService Success tests', () => {
it('should call DELETE', inject([NetworkService, MockBackend], (networkService) => {
networkService.deleteJson(testUrl).then((res: Message<any>) => {
expect(res.result).toBe(testResponse);
networkService.deleteJson(testUrl).then((res: any) => {
expect(res).toBe(testResponse);
});
}));
});