summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/api/telemetry.service.spec.ts
blob: a90fcff7a75b9e79c8d8b6004a3cb55148df0a17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';

import { configureTestBed } from '~/testing/unit-test-helper';
import { TelemetryService } from './telemetry.service';

describe('TelemetryService', () => {
  let service: TelemetryService;
  let httpTesting: HttpTestingController;

  configureTestBed({
    imports: [HttpClientTestingModule],
    providers: [TelemetryService]
  });

  beforeEach(() => {
    service = TestBed.inject(TelemetryService);
    httpTesting = TestBed.inject(HttpTestingController);
  });

  afterEach(() => {
    httpTesting.verify();
  });

  it('should be created', () => {
    expect(service).toBeTruthy();
  });

  it('should call getReport', () => {
    service.getReport().subscribe();
    const req = httpTesting.expectOne('api/telemetry/report');
    expect(req.request.method).toBe('GET');
  });

  it('should call enable to enable module', () => {
    service.enable(true).subscribe();
    const req = httpTesting.expectOne('api/telemetry');
    expect(req.request.method).toBe('PUT');
    expect(req.request.body.enable).toBe(true);
    expect(req.request.body.license_name).toBe('sharing-1-0');
  });

  it('should call enable to disable module', () => {
    service.enable(false).subscribe();
    const req = httpTesting.expectOne('api/telemetry');
    expect(req.request.method).toBe('PUT');
    expect(req.request.body.enable).toBe(false);
    expect(req.request.body.license_name).toBeUndefined();
  });

  it('should call enable to enable module by default', () => {
    service.enable().subscribe();
    const req = httpTesting.expectOne('api/telemetry');
    expect(req.request.method).toBe('PUT');
    expect(req.request.body.enable).toBe(true);
    expect(req.request.body.license_name).toBe('sharing-1-0');
  });
});