|
|
|
@ -13,7 +13,8 @@ import { |
|
|
|
ApiUrlConfig, |
|
|
|
BackupDto, |
|
|
|
BackupsService, |
|
|
|
DateTime |
|
|
|
DateTime, |
|
|
|
RestoreDto |
|
|
|
} from './../'; |
|
|
|
|
|
|
|
describe('BackupsService', () => { |
|
|
|
@ -74,6 +75,84 @@ describe('BackupsService', () => { |
|
|
|
]); |
|
|
|
})); |
|
|
|
|
|
|
|
it('should make get request to get restore', |
|
|
|
inject([BackupsService, HttpTestingController], (backupsService: BackupsService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
let restore: RestoreDto; |
|
|
|
|
|
|
|
backupsService.getRestore().subscribe(result => { |
|
|
|
restore = result!; |
|
|
|
}); |
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/apps/restore'); |
|
|
|
|
|
|
|
expect(req.request.method).toEqual('GET'); |
|
|
|
expect(req.request.headers.get('If-Match')).toBeNull(); |
|
|
|
|
|
|
|
req.flush({ |
|
|
|
url: 'http://url', |
|
|
|
started: '2017-02-03', |
|
|
|
stopped: '2017-02-04', |
|
|
|
status: 'Failed', |
|
|
|
log: [ |
|
|
|
'log1', |
|
|
|
'log2' |
|
|
|
] |
|
|
|
}); |
|
|
|
|
|
|
|
expect(restore!).toEqual( |
|
|
|
new RestoreDto('http://url', |
|
|
|
DateTime.parseISO_UTC('2017-02-03'), |
|
|
|
DateTime.parseISO_UTC('2017-02-04'), |
|
|
|
'Failed', |
|
|
|
[ |
|
|
|
'log1', |
|
|
|
'log2' |
|
|
|
])); |
|
|
|
})); |
|
|
|
|
|
|
|
it('should return null when get restore return 404', |
|
|
|
inject([BackupsService, HttpTestingController], (backupsService: BackupsService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
let restore: RestoreDto | null; |
|
|
|
|
|
|
|
backupsService.getRestore().subscribe(result => { |
|
|
|
restore = result; |
|
|
|
}); |
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/apps/restore'); |
|
|
|
|
|
|
|
expect(req.request.method).toEqual('GET'); |
|
|
|
expect(req.request.headers.get('If-Match')).toBeNull(); |
|
|
|
|
|
|
|
req.flush({}, { status: 404, statusText: '404' }); |
|
|
|
|
|
|
|
expect(restore!).toBeNull(); |
|
|
|
})); |
|
|
|
|
|
|
|
it('should throw error when get restore return non 404', |
|
|
|
inject([BackupsService, HttpTestingController], (backupsService: BackupsService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
let restore: RestoreDto | null; |
|
|
|
let error: any; |
|
|
|
|
|
|
|
backupsService.getRestore().subscribe(result => { |
|
|
|
restore = result; |
|
|
|
}, err => { |
|
|
|
error = err; |
|
|
|
}); |
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/apps/restore'); |
|
|
|
|
|
|
|
expect(req.request.method).toEqual('GET'); |
|
|
|
expect(req.request.headers.get('If-Match')).toBeNull(); |
|
|
|
|
|
|
|
req.flush({}, { status: 500, statusText: '500' }); |
|
|
|
|
|
|
|
expect(restore!).toBeUndefined(); |
|
|
|
expect(error)!.toBeDefined(); |
|
|
|
})); |
|
|
|
|
|
|
|
it('should make post request to start backup', |
|
|
|
inject([BackupsService, HttpTestingController], (backupsService: BackupsService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
@ -87,6 +166,19 @@ describe('BackupsService', () => { |
|
|
|
req.flush({}); |
|
|
|
})); |
|
|
|
|
|
|
|
it('should make post request to start restore', |
|
|
|
inject([BackupsService, HttpTestingController], (backupsService: BackupsService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
backupsService.postRestore('http://url').subscribe(); |
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/apps/restore'); |
|
|
|
|
|
|
|
expect(req.request.method).toEqual('POST'); |
|
|
|
expect(req.request.headers.get('If-Match')).toBeNull(); |
|
|
|
|
|
|
|
req.flush({}); |
|
|
|
})); |
|
|
|
|
|
|
|
it('should make delete request to remove language', |
|
|
|
inject([BackupsService, HttpTestingController], (backupsService: BackupsService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
|