Snapshot and Version services tests

This commit is contained in:
Dominik Ziajka 2018-03-30 11:38:08 +02:00
parent 6513cb565c
commit 51f4fe4627
2 changed files with 90 additions and 14 deletions

View File

@ -1,26 +1,64 @@
import { TestBed, inject } from '@angular/core/testing';
import { SnapshotService } from './snapshot.service';
import { HttpClient } from '@angular/common/http';
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing';
import { HttpServer } from './http-server.service';
import { Server } from '../models/server';
import { Node } from '../../cartography/shared/models/node';
import { Port } from '../models/port';
import { getTestServer } from './testing';
import { SnapshotService } from './snapshot.service';
import { Snapshot } from '../models/snapshot';
class MockedHttpServer {
post(server: any, url: string, data: any) {}
get(server: any, url: string, data: any) {}
}
describe('SnapshotService', () => {
let httpClient: HttpClient;
let httpTestingController: HttpTestingController;
let httpServer: HttpServer;
let service: SnapshotService;
let server: Server;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
SnapshotService,
{provide: HttpServer, useClass: MockedHttpServer}
imports: [
HttpClientTestingModule
],
providers: [
HttpServer,
SnapshotService
]
});
httpClient = TestBed.get(HttpClient);
httpTestingController = TestBed.get(HttpTestingController);
httpServer = TestBed.get(HttpServer);
service = TestBed.get(SnapshotService);
server = getTestServer();
});
afterEach(() => {
httpTestingController.verify();
});
it('should be created', inject([SnapshotService], (service: SnapshotService) => {
expect(service).toBeTruthy();
}));
it('should create snapshot', inject([SnapshotService], (service: SnapshotService) => {
const snapshot = new Snapshot();
service.create(server, "myproject", snapshot).subscribe();
const req = httpTestingController.expectOne(
'http://127.0.0.1:3080/v2/projects/myproject/snapshots');
expect(req.request.method).toEqual("POST");
expect(req.request.body).toEqual(snapshot);
}));
it('should list snapshots', inject([SnapshotService], (service: SnapshotService) => {
service.list(server, "myproject").subscribe();
const req = httpTestingController.expectOne(
'http://127.0.0.1:3080/v2/projects/myproject/snapshots');
expect(req.request.method).toEqual("GET");
}))
});

View File

@ -1,15 +1,53 @@
import { TestBed, inject } from '@angular/core/testing';
import { HttpClient } from '@angular/common/http';
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing';
import { HttpServer } from './http-server.service';
import { Server } from '../models/server';
import { Node } from '../../cartography/shared/models/node';
import { Port } from '../models/port';
import { getTestServer } from './testing';
import { VersionService } from './version.service';
describe('VersionService', () => {
let httpClient: HttpClient;
let httpTestingController: HttpTestingController;
let httpServer: HttpServer;
let service: VersionService;
let server: Server;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [VersionService]
imports: [
HttpClientTestingModule
],
providers: [
HttpServer,
VersionService
]
});
httpClient = TestBed.get(HttpClient);
httpTestingController = TestBed.get(HttpTestingController);
httpServer = TestBed.get(HttpServer);
service = TestBed.get(VersionService);
server = getTestServer();
});
// it('should be created', inject([VersionService], (service: VersionService) => {
// expect(service).toBeTruthy();
// }));
afterEach(() => {
httpTestingController.verify();
});
it('should be created', inject([VersionService], (service: VersionService) => {
expect(service).toBeTruthy();
}));
it('should get version', inject([VersionService], (service: VersionService) => {
service.get(server);
const req = httpTestingController.expectOne(
'http://127.0.0.1:3080/v2/version');
expect(req.request.method).toEqual("GET");
}));
});