2017-11-23 13:18:23 +01:00
|
|
|
import { TestBed, inject } from '@angular/core/testing';
|
|
|
|
|
2018-03-30 11:38:08 +02:00
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing';
|
2018-01-18 12:39:36 +01:00
|
|
|
import { HttpServer } from './http-server.service';
|
2018-03-30 11:38:08 +02:00
|
|
|
import { Server } from '../models/server';
|
|
|
|
import { getTestServer } from './testing';
|
|
|
|
import { SnapshotService } from './snapshot.service';
|
|
|
|
import { Snapshot } from '../models/snapshot';
|
2019-01-15 11:15:54 +01:00
|
|
|
import { AppTestingModule } from '../testing/app-testing/app-testing.module';
|
2017-11-23 13:18:23 +01:00
|
|
|
|
|
|
|
describe('SnapshotService', () => {
|
2018-03-30 11:38:08 +02:00
|
|
|
let httpClient: HttpClient;
|
|
|
|
let httpTestingController: HttpTestingController;
|
|
|
|
let httpServer: HttpServer;
|
|
|
|
let service: SnapshotService;
|
|
|
|
let server: Server;
|
|
|
|
|
2017-11-23 13:18:23 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
TestBed.configureTestingModule({
|
2019-01-15 11:15:54 +01:00
|
|
|
imports: [HttpClientTestingModule, AppTestingModule],
|
|
|
|
providers: [HttpServer, SnapshotService]
|
2017-11-23 13:18:23 +01:00
|
|
|
});
|
2018-03-30 11:38:08 +02:00
|
|
|
|
|
|
|
httpClient = TestBed.get(HttpClient);
|
|
|
|
httpTestingController = TestBed.get(HttpTestingController);
|
|
|
|
httpServer = TestBed.get(HttpServer);
|
|
|
|
service = TestBed.get(SnapshotService);
|
|
|
|
server = getTestServer();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
httpTestingController.verify();
|
2017-11-23 13:18:23 +01:00
|
|
|
});
|
|
|
|
|
2018-01-18 12:39:36 +01:00
|
|
|
it('should be created', inject([SnapshotService], (service: SnapshotService) => {
|
|
|
|
expect(service).toBeTruthy();
|
|
|
|
}));
|
2018-03-30 11:38:08 +02:00
|
|
|
|
|
|
|
it('should create snapshot', inject([SnapshotService], (service: SnapshotService) => {
|
|
|
|
const snapshot = new Snapshot();
|
2019-01-15 11:15:54 +01:00
|
|
|
service.create(server, 'myproject', snapshot).subscribe();
|
2018-03-30 11:38:08 +02:00
|
|
|
|
2019-01-15 11:15:54 +01:00
|
|
|
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/projects/myproject/snapshots');
|
|
|
|
expect(req.request.method).toEqual('POST');
|
2018-03-30 11:38:08 +02:00
|
|
|
expect(req.request.body).toEqual(snapshot);
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should list snapshots', inject([SnapshotService], (service: SnapshotService) => {
|
2019-01-15 11:15:54 +01:00
|
|
|
service.list(server, 'myproject').subscribe();
|
2018-03-30 11:38:08 +02:00
|
|
|
|
2019-01-15 11:15:54 +01:00
|
|
|
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/projects/myproject/snapshots');
|
|
|
|
expect(req.request.method).toEqual('GET');
|
|
|
|
}));
|
2017-11-23 13:18:23 +01:00
|
|
|
});
|