Browse Source

Tests fixed.

pull/382/head
Sebastian 7 years ago
parent
commit
bce63be871
  1. 57
      src/Squidex/app/shared/services/backups.service.spec.ts
  2. 8
      src/Squidex/app/shared/state/backups.state.spec.ts

57
src/Squidex/app/shared/services/backups.service.spec.ts

@ -16,6 +16,7 @@ import {
BackupsService, BackupsService,
DateTime, DateTime,
Resource, Resource,
ResourceLinks,
RestoreDto RestoreDto
} from '@app/shared/internal'; } from '@app/shared/internal';
@ -52,30 +53,16 @@ describe('BackupsService', () => {
expect(req.request.headers.get('If-Match')).toBeNull(); expect(req.request.headers.get('If-Match')).toBeNull();
req.flush({ req.flush({
items: [{ items: [
id: '1', backupResponse(12),
started: '2017-02-03', backupResponse(13)
stopped: '2017-02-04', ]
handledEvents: 13,
handledAssets: 17,
status: 'Failed',
_links: {}
},
{
id: '2',
started: '2018-02-03',
stopped: null,
handledEvents: 23,
handledAssets: 27,
status: 'Completed',
_links: {}
}]
}); });
expect(backups!).toEqual( expect(backups!).toEqual(
new BackupsDto([ new BackupsDto([
new BackupDto({}, '1', DateTime.parseISO_UTC('2017-02-03'), DateTime.parseISO_UTC('2017-02-04'), 13, 17, 'Failed'), createBackup(12),
new BackupDto({}, '2', DateTime.parseISO_UTC('2018-02-03'), null, 23, 27, 'Completed') createBackup(13)
])); ]));
})); }));
@ -203,4 +190,32 @@ describe('BackupsService', () => {
req.flush({}); req.flush({});
})); }));
});
function backupResponse(id: number) {
return {
id: `id${id}`,
started: `${id % 1000 + 2000}-12-12T10:10:00`,
stopped: id % 2 === 0 ? `${id % 1000 + 2000}-11-11T10:10:00` : null,
handledEvents: id * 17,
handledAssets: id * 23,
status: id % 2 === 0 ? 'Status' : 'Failed',
_links: {
download: { method: 'GET', href: '/api/backups/1' }
}
};
}
});
export function createBackup(id: number) {
const links: ResourceLinks = {
download: { method: 'GET', href: '/api/backups/1' }
};
return new BackupDto(links,
`id${id}`,
DateTime.parseISO_UTC(`${id % 1000 + 2000}-12-12T10:10:00`),
id % 2 === 0 ? DateTime.parseISO_UTC(`${id % 1000 + 2000}-11-11T10:10:00`) : null,
id * 17,
id * 23,
id % 2 === 0 ? 'Status' : 'Failed');
}

8
src/Squidex/app/shared/state/backups.state.spec.ts

@ -10,24 +10,24 @@ import { onErrorResumeNext } from 'rxjs/operators';
import { IMock, It, Mock, Times } from 'typemoq'; import { IMock, It, Mock, Times } from 'typemoq';
import { import {
BackupDto,
BackupsDto, BackupsDto,
BackupsService, BackupsService,
BackupsState, BackupsState,
DateTime,
DialogService DialogService
} from '@app/shared/internal'; } from '@app/shared/internal';
import { TestValues } from './_test-helpers'; import { TestValues } from './_test-helpers';
import { createBackup } from './../services/backups.service.spec';
describe('BackupsState', () => { describe('BackupsState', () => {
const { const {
app, app,
appsState appsState
} = TestValues; } = TestValues;
const backup1 = new BackupDto({}, 'id1', DateTime.now(), null, 1, 1, 'Started'); const backup1 = createBackup(12);
const backup2 = new BackupDto({}, 'id2', DateTime.now(), null, 2, 2, 'Started'); const backup2 = createBackup(13);
let dialogs: IMock<DialogService>; let dialogs: IMock<DialogService>;
let backupsService: IMock<BackupsService>; let backupsService: IMock<BackupsService>;

Loading…
Cancel
Save