Skip to content
Snippets Groups Projects
Commit f08fda9b authored by Kristof De Langhe's avatar Kristof De Langhe
Browse files

58789: Added more test coverage

parent 31b3a1fd
Branches
Tags
No related merge requests found
import { PageInfo } from '../shared/page-info.model';
import { DSOResponseParsingService } from './dso-response-parsing.service';
import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model';
import {
RegistryBitstreamformatsSuccessResponse
} from '../cache/response.models';
import { RegistryBitstreamformatsResponseParsingService } from './registry-bitstreamformats-response-parsing.service';
describe('RegistryBitstreamformatsResponseParsingService', () => {
let service: RegistryBitstreamformatsResponseParsingService;
const mockDSOParser = Object.assign({
processPageInfo: () => new PageInfo()
}) as DSOResponseParsingService;
const data = Object.assign({
payload: {
_embedded: {
bitstreamformats: [
{
uuid: 'uuid-1',
description: 'a description'
},
{
uuid: 'uuid-2',
description: 'another description'
},
]
}
}
}) as DSpaceRESTV2Response;
beforeEach(() => {
service = new RegistryBitstreamformatsResponseParsingService(mockDSOParser);
});
it('should parse the data correctly', () => {
const response = service.parse(null, data);
expect(response.constructor).toBe(RegistryBitstreamformatsSuccessResponse);
});
});
import { PageInfo } from '../shared/page-info.model';
import { DSOResponseParsingService } from './dso-response-parsing.service';
import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model';
import {
RegistryMetadatafieldsSuccessResponse
} from '../cache/response.models';
import { RegistryMetadatafieldsResponseParsingService } from './registry-metadatafields-response-parsing.service';
describe('RegistryMetadatafieldsResponseParsingService', () => {
let service: RegistryMetadatafieldsResponseParsingService;
const mockDSOParser = Object.assign({
processPageInfo: () => new PageInfo()
}) as DSOResponseParsingService;
const data = Object.assign({
payload: {
_embedded: {
metadatafields: [
{
id: 1,
element: 'element',
qualifier: 'qualifier',
scopeNote: 'a scope note',
_embedded: {
schema: {
id: 1,
prefix: 'test',
namespace: 'test namespace'
}
}
},
{
id: 2,
element: 'secondelement',
qualifier: 'secondqualifier',
scopeNote: 'a second scope note',
_embedded: {
schema: {
id: 1,
prefix: 'test',
namespace: 'test namespace'
}
}
},
]
}
}
}) as DSpaceRESTV2Response;
const emptyData = Object.assign({
payload: {}
}) as DSpaceRESTV2Response;
beforeEach(() => {
service = new RegistryMetadatafieldsResponseParsingService(mockDSOParser);
});
it('should parse the data correctly', () => {
const response = service.parse(null, data);
expect(response.constructor).toBe(RegistryMetadatafieldsSuccessResponse);
});
it('should not produce an error and parse the data correctly when the data is empty', () => {
const response = service.parse(null, emptyData);
expect(response.constructor).toBe(RegistryMetadatafieldsSuccessResponse);
});
});
import { RegistryMetadataschemasResponseParsingService } from './registry-metadataschemas-response-parsing.service';
import { PageInfo } from '../shared/page-info.model';
import { DSOResponseParsingService } from './dso-response-parsing.service';
import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model';
import { RegistryMetadataschemasSuccessResponse } from '../cache/response.models';
describe('RegistryMetadataschemasResponseParsingService', () => {
let service: RegistryMetadataschemasResponseParsingService;
const mockDSOParser = Object.assign({
processPageInfo: () => new PageInfo()
}) as DSOResponseParsingService;
const data = Object.assign({
payload: {
_embedded: {
metadataschemas: [
{
id: 1,
prefix: 'test',
namespace: 'test namespace'
},
{
id: 2,
prefix: 'second',
namespace: 'second test namespace'
}
]
}
}
}) as DSpaceRESTV2Response;
const emptyData = Object.assign({
payload: {}
}) as DSpaceRESTV2Response;
beforeEach(() => {
service = new RegistryMetadataschemasResponseParsingService(mockDSOParser);
});
it('should parse the data correctly', () => {
const response = service.parse(null, data);
expect(response.constructor).toBe(RegistryMetadataschemasSuccessResponse);
});
it('should not produce an error and parse the data correctly when the data is empty', () => {
const response = service.parse(null, emptyData);
expect(response.constructor).toBe(RegistryMetadataschemasSuccessResponse);
});
});
......@@ -4,7 +4,7 @@ import { requestReducer, RequestState } from './request.reducer';
import {
RequestCompleteAction,
RequestConfigureAction,
RequestExecuteAction, ResetResponseTimestampsAction
RequestExecuteAction, RequestRemoveAction, ResetResponseTimestampsAction
} from './request.actions';
import { GetRequest } from './request.models';
import { RestResponse } from '../cache/response.models';
......@@ -110,4 +110,13 @@ describe('requestReducer', () => {
expect(newState[id1].response.statusCode).toEqual(response.statusCode);
expect(newState[id1].response.timeAdded).toBe(timeStamp);
});
it('should remove the correct request, in response to a REMOVE action', () => {
const state = testState;
const action = new RequestRemoveAction(id1);
const newState = requestReducer(state, action);
expect(newState[id1]).toBeUndefined();
});
});
import * as deepFreeze from 'deep-freeze';
import { IndexName, indexReducer, IndexState } from './index.reducer';
import { AddToIndexAction, RemoveFromIndexByValueAction } from './index.actions';
import { AddToIndexAction, RemoveFromIndexBySubstringAction, RemoveFromIndexByValueAction } from './index.actions';
class NullAction extends AddToIndexAction {
type = null;
......@@ -59,4 +59,13 @@ describe('requestReducer', () => {
expect(newState[IndexName.OBJECT][key1]).toBeUndefined();
});
it('should remove the given \'value\' from its corresponding \'key\' in the correct substate, in response to a REMOVE_BY_SUBSTRING action', () => {
const state = testState;
const action = new RemoveFromIndexBySubstringAction(IndexName.OBJECT, key1);
const newState = indexReducer(state, action);
expect(newState[IndexName.OBJECT][key1]).toBeUndefined();
});
});
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment