93219: Add (more) reusable functions to test DataService composition

Data services that implement *Data interfaces should include the appropriate test functions in their specs.
These go over all methods in the interface & check that they're "wired up" correctly.

See e.g. the change in ExternalSourceDataService for an issue that is easy to miss but was highlighted by these new tests
This commit is contained in:
Yury Bondarenko
2022-09-12 17:37:54 +02:00
parent 8b4dbbad55
commit 147c7180d0
34 changed files with 442 additions and 75 deletions

View File

@@ -17,10 +17,38 @@ import { HALEndpointServiceStub } from '../../../shared/testing/hal-endpoint-ser
import { getMockRemoteDataBuildService } from '../../../shared/mocks/remote-data-build.service.mock';
import { RemoteData } from '../remote-data';
import { RequestEntryState } from '../request-entry-state.model';
import { PutDataImpl } from './put-data';
import { PutData, PutDataImpl } from './put-data';
import { RestRequestMethod } from '../rest-request-method';
import { DSpaceObject } from '../../shared/dspace-object.model';
/**
* Tests whether calls to `PutData` methods are correctly patched through in a concrete data service that implements it
*/
export function testPutDataImplementation(serviceFactory: () => PutData<any>) {
let service;
describe('PutData implementation', () => {
const OBJ = Object.assign(new DSpaceObject(), {
uuid: '08eec68f-45e4-47a3-80c5-f0beb5627079',
});
beforeAll(() => {
service = serviceFactory();
(service as any).putData = jasmine.createSpyObj('putData', {
put: 'TEST put',
});
});
it('should handle calls to put', () => {
const out: any = service.put(OBJ);
expect((service as any).putData.put).toHaveBeenCalledWith(OBJ);
expect(out).toBe('TEST put');
});
});
}
const endpoint = 'https://rest.api/core';
class TestService extends PutDataImpl<any> {