mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-20 17:52:46 +00:00
NodeService tests
This commit is contained in:
parent
d5807070f4
commit
d8d6398d26
@ -4,7 +4,7 @@ import { HttpClient } from "@angular/common/http";
|
||||
|
||||
import { Server } from '../models/server';
|
||||
import { HttpServer } from './http-server.service';
|
||||
|
||||
import { getTestServer } from './testing';
|
||||
|
||||
class MyType {
|
||||
id: number;
|
||||
@ -31,10 +31,7 @@ describe('HttpServer', () => {
|
||||
httpTestingController = TestBed.get(HttpTestingController);
|
||||
service = TestBed.get(HttpServer);
|
||||
|
||||
server = new Server();
|
||||
server.ip = "127.0.0.1";
|
||||
server.port = 3080;
|
||||
server.authorization = "none";
|
||||
server = getTestServer();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -7,6 +7,7 @@ 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';
|
||||
|
||||
describe('LinkService', () => {
|
||||
let httpClient: HttpClient;
|
||||
@ -30,11 +31,7 @@ describe('LinkService', () => {
|
||||
httpTestingController = TestBed.get(HttpTestingController);
|
||||
httpServer = TestBed.get(HttpServer);
|
||||
service = TestBed.get(LinkService);
|
||||
|
||||
server = new Server();
|
||||
server.ip = "127.0.0.1";
|
||||
server.port = 3080;
|
||||
server.authorization = "none";
|
||||
server = getTestServer();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@ -64,6 +61,7 @@ describe('LinkService', () => {
|
||||
service.createLink(server, sourceNode, sourcePort, targetNode, targetPort).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/projects/myproject/links');
|
||||
expect(req.request.method).toEqual("POST");
|
||||
expect(req.request.body).toEqual({"nodes": [
|
||||
{
|
||||
node_id: "sourceid",
|
||||
|
@ -1,15 +1,137 @@
|
||||
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 { NodeService } from './node.service';
|
||||
import { Appliance } from '../models/appliance';
|
||||
import { Project } from '../models/project';
|
||||
|
||||
describe('NodeService', () => {
|
||||
let httpClient: HttpClient;
|
||||
let httpTestingController: HttpTestingController;
|
||||
let httpServer: HttpServer;
|
||||
let service: NodeService;
|
||||
let server: Server;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [NodeService]
|
||||
imports: [
|
||||
HttpClientTestingModule
|
||||
],
|
||||
providers: [
|
||||
HttpServer,
|
||||
NodeService
|
||||
]
|
||||
});
|
||||
|
||||
httpClient = TestBed.get(HttpClient);
|
||||
httpTestingController = TestBed.get(HttpTestingController);
|
||||
httpServer = TestBed.get(HttpServer);
|
||||
service = TestBed.get(NodeService);
|
||||
server = getTestServer();
|
||||
});
|
||||
|
||||
// it('should be created', inject([NodeService], (service: NodeService) => {
|
||||
// expect(service).toBeTruthy();
|
||||
// }));
|
||||
afterEach(() => {
|
||||
httpTestingController.verify();
|
||||
});
|
||||
|
||||
it('should be created', inject([NodeService], (service: NodeService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should start node', inject([NodeService], (service: NodeService) => {
|
||||
const node = new Node();
|
||||
node.project_id = "myproject";
|
||||
node.node_id = "id";
|
||||
|
||||
service.start(server, node).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne(
|
||||
'http://127.0.0.1:3080/v2/projects/myproject/nodes/id/start');
|
||||
expect(req.request.method).toEqual("POST");
|
||||
expect(req.request.body).toEqual({});
|
||||
}));
|
||||
|
||||
it('should stop node', inject([NodeService], (service: NodeService) => {
|
||||
const node = new Node();
|
||||
node.project_id = "myproject";
|
||||
node.node_id = "id";
|
||||
|
||||
service.stop(server, node).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne(
|
||||
'http://127.0.0.1:3080/v2/projects/myproject/nodes/id/stop');
|
||||
expect(req.request.method).toEqual("POST");
|
||||
expect(req.request.body).toEqual({});
|
||||
}));
|
||||
|
||||
it('should createFromAppliance node', inject([NodeService], (service: NodeService) => {
|
||||
const project = new Project();
|
||||
project.project_id = "myproject";
|
||||
const appliance = new Appliance();
|
||||
appliance.appliance_id = "myappliance";
|
||||
|
||||
service.createFromAppliance(server, project, appliance, 10, 20, "compute").subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne(
|
||||
'http://127.0.0.1:3080/v2/projects/myproject/appliances/myappliance');
|
||||
expect(req.request.method).toEqual("POST");
|
||||
expect(req.request.body).toEqual({
|
||||
'x': 10, 'y': 20, 'compute_id': 'compute'});
|
||||
}));
|
||||
|
||||
it('should updatePosition of node', inject([NodeService], (service: NodeService) => {
|
||||
const node = new Node();
|
||||
node.project_id = "myproject";
|
||||
node.node_id = "id";
|
||||
|
||||
service.updatePosition(server, node, 10, 20).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne(
|
||||
'http://127.0.0.1:3080/v2/projects/myproject/nodes/id');
|
||||
expect(req.request.method).toEqual("PUT");
|
||||
expect(req.request.body).toEqual({
|
||||
'x': 10,
|
||||
'y': 20
|
||||
});
|
||||
}));
|
||||
|
||||
it('should update node', inject([NodeService], (service: NodeService) => {
|
||||
const node = new Node();
|
||||
node.project_id = "myproject";
|
||||
node.node_id = "id";
|
||||
node.x = 10;
|
||||
node.y = 20;
|
||||
node.z = 30;
|
||||
|
||||
service.update(server, node).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne(
|
||||
'http://127.0.0.1:3080/v2/projects/myproject/nodes/id');
|
||||
expect(req.request.method).toEqual("PUT");
|
||||
expect(req.request.body).toEqual({
|
||||
'x': 10,
|
||||
'y': 20,
|
||||
'z': 30
|
||||
});
|
||||
}));
|
||||
|
||||
it('should delete node', inject([NodeService], (service: NodeService) => {
|
||||
const node = new Node();
|
||||
node.project_id = "myproject";
|
||||
node.node_id = "id";
|
||||
|
||||
service.delete(server, node).subscribe();
|
||||
|
||||
const req = httpTestingController.expectOne(
|
||||
'http://127.0.0.1:3080/v2/projects/myproject/nodes/id');
|
||||
expect(req.request.method).toEqual("DELETE");
|
||||
|
||||
}));
|
||||
|
||||
});
|
||||
|
9
src/app/shared/services/testing.ts
Normal file
9
src/app/shared/services/testing.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Server } from "../models/server";
|
||||
|
||||
export function getTestServer(): Server {
|
||||
const server = new Server();
|
||||
server.ip = "127.0.0.1";
|
||||
server.port = 3080;
|
||||
server.authorization = "none";
|
||||
return server;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user