Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

147 lines
4.8 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { inject, TestBed } from '@angular/core/testing';
import { ApiUrlConfig, CallsUsageDto, CallsUsagePerDateDto, CurrentStorageDto, DateTime, StorageUsagePerDateDto, UsagesService } from '@app/shared/internal';
describe('UsagesService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule
],
providers: [
UsagesService,
{ provide: ApiUrlConfig, useValue: new ApiUrlConfig('http://service/p/') }
]
});
});
afterEach(inject([HttpTestingController], (httpMock: HttpTestingController) => {
httpMock.verify();
}));
it('should make get request to get calls usages',
inject([UsagesService, HttpTestingController], (usagesService: UsagesService, httpMock: HttpTestingController) => {
let usages: CallsUsageDto;
usagesService.getCallsUsages('my-app', '2017-10-12', '2017-10-13').subscribe(result => {
usages = result;
});
const req = httpMock.expectOne('http://service/p/api/apps/my-app/usages/calls/2017-10-12/2017-10-13');
expect(req.request.method).toEqual('GET');
expect(req.request.headers.get('If-Match')).toBeNull();
req.flush({
allowedCalls: 100,
totalBytes: 1024,
totalCalls: 40,
averageElapsedMs: 12.4,
details: {
category1: [
{
date: '2017-10-12',
totalBytes: 10,
totalCalls: 130,
averageElapsedMs: 12.3
},
{
date: '2017-10-13',
totalBytes: 13,
totalCalls: 170,
averageElapsedMs: 33.3
}
]
}
});
expect(usages!).toEqual(
new CallsUsageDto(100, 1024, 40, 12.4, {
category1: [
new CallsUsagePerDateDto(DateTime.parseISO('2017-10-12'), 10, 130, 12.3),
new CallsUsagePerDateDto(DateTime.parseISO('2017-10-13'), 13, 170, 33.3)
]
})
);
}));
it('should make get request to get storage usages',
inject([UsagesService, HttpTestingController], (usagesService: UsagesService, httpMock: HttpTestingController) => {
let usages: ReadonlyArray<StorageUsagePerDateDto>;
usagesService.getStorageUsages('my-app', '2017-10-12', '2017-10-13').subscribe(result => {
usages = result;
});
const req = httpMock.expectOne('http://service/p/api/apps/my-app/usages/storage/2017-10-12/2017-10-13');
expect(req.request.method).toEqual('GET');
expect(req.request.headers.get('If-Match')).toBeNull();
req.flush([
{
date: '2017-10-12',
totalCount: 10,
totalSize: 130
},
{
date: '2017-10-13',
totalCount: 13,
totalSize: 170
}
]);
expect(usages!).toEqual(
[
new StorageUsagePerDateDto(DateTime.parseISO('2017-10-12'), 10, 130),
new StorageUsagePerDateDto(DateTime.parseISO('2017-10-13'), 13, 170)
]);
}));
it('should make get request to get today storage',
inject([UsagesService, HttpTestingController], (usagesService: UsagesService, httpMock: HttpTestingController) => {
let usages: CurrentStorageDto;
usagesService.getTodayStorage('my-app').subscribe(result => {
usages = result;
});
const req = httpMock.expectOne('http://service/p/api/apps/my-app/usages/storage/today');
expect(req.request.method).toEqual('GET');
expect(req.request.headers.get('If-Match')).toBeNull();
req.flush({ size: 130, maxAllowed: 150 });
expect(usages!).toEqual(new CurrentStorageDto(130, 150));
}));
it('should make get request to get log',
inject([UsagesService, HttpTestingController], (usagesService: UsagesService, httpMock: HttpTestingController) => {
let url: string;
usagesService.getLog('my-app').subscribe(result => {
url = result;
});
const req = httpMock.expectOne('http://service/p/api/apps/my-app/usages/log');
expect(req.request.method).toEqual('GET');
expect(req.request.headers.get('If-Match')).toBeNull();
req.flush({ downloadUrl: 'download/url' });
expect(url!).toEqual('download/url');
}));
});