Skip to content

Commit af2e097

Browse files
committed
move embed item fix to SubmissionJsonPatchOperationsService
1 parent a3540be commit af2e097

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/app/core/json-patch/json-patch-operations.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ describe('JsonPatchOperationsService test suite', () => {
156156
});
157157

158158
it('should send a new SubmissionPatchRequest', () => {
159-
const expected = new SubmissionPatchRequest(requestService.generateRequestId(), resourceHref + '?embed=item', patchOpBody);
159+
const expected = new SubmissionPatchRequest(requestService.generateRequestId(), resourceHref, patchOpBody);
160160
scheduler.schedule(() => service.jsonPatchByResourceType(resourceEndpoint, resourceScope, testJsonPatchResourceType).subscribe());
161161
scheduler.flush();
162162

@@ -246,7 +246,7 @@ describe('JsonPatchOperationsService test suite', () => {
246246
});
247247

248248
it('should send a new SubmissionPatchRequest', () => {
249-
const expected = new SubmissionPatchRequest(requestService.generateRequestId(), resourceHref + '?embed=item', patchOpBody);
249+
const expected = new SubmissionPatchRequest(requestService.generateRequestId(), resourceHref, patchOpBody);
250250
scheduler.schedule(() => service.jsonPatchByResourceID(resourceEndpoint, resourceScope, testJsonPatchResourceType, testJsonPatchResourceId).subscribe());
251251
scheduler.flush();
252252

src/app/core/json-patch/json-patch-operations.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { PatchRequest } from '../data/request.models';
2828
import { RequestService } from '../data/request.service';
2929
import { HALEndpointService } from '../shared/hal-endpoint.service';
3030
import { getFirstCompletedRemoteData } from '../shared/operators';
31-
import { URLCombiner } from '../url-combiner/url-combiner';
3231
import { JsonPatchOperationModel } from './json-patch.model';
3332
import {
3433
CommitPatchOperationsAction,
@@ -145,7 +144,7 @@ export abstract class JsonPatchOperationsService<ResponseDefinitionDomain, Patch
145144
* instance of PatchRequestDefinition
146145
*/
147146
protected getRequestInstance(uuid: string, href: string, body?: any): PatchRequestDefinition {
148-
return new this.patchRequestConstructor(uuid, new URLCombiner(href, '?embed=item').toString(), body);
147+
return new this.patchRequestConstructor(uuid, href, body);
149148
}
150149

151150
protected getEndpointByIDHref(endpoint, resourceID): string {

src/app/core/submission/submission-json-patch-operations.service.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ describe('SubmissionJsonPatchOperationsService', () => {
1717
const rdbService = {} as RemoteDataBuildService;
1818
const halEndpointService = {} as HALEndpointService;
1919

20+
const uuid = '91ecbeda-99fe-42ac-9430-b9b75af56f78';
21+
const href = 'https://rest.api/some/self/link?with=maybe&a=few&other=parameters';
22+
2023
function initTestService() {
2124
return new SubmissionJsonPatchOperationsService(
2225
requestService,
@@ -36,4 +39,16 @@ describe('SubmissionJsonPatchOperationsService', () => {
3639
expect((service as any).patchRequestConstructor).toEqual(SubmissionPatchRequest);
3740
});
3841

42+
describe(`getRequestInstance`, () => {
43+
it(`should add a parameter to embed the item to the request URL`, () => {
44+
const result = (service as any).getRequestInstance(uuid, href);
45+
const resultURL = new URL(result.href);
46+
expect(resultURL.searchParams.get('embed')).toEqual('item');
47+
48+
// if we delete the embed item param, it should be identical to the original url
49+
resultURL.searchParams.delete('embed', 'item');
50+
expect(href).toEqual(resultURL.toString());
51+
});
52+
});
53+
3954
});

src/app/core/submission/submission-json-patch-operations.service.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { RequestService } from '../data/request.service';
88
import { JsonPatchOperationsService } from '../json-patch/json-patch-operations.service';
99
import { HALEndpointService } from '../shared/hal-endpoint.service';
1010
import { SubmitDataResponseDefinitionObject } from '../shared/submit-data-response-definition.model';
11+
import { URLCombiner } from '../url-combiner/url-combiner';
1112

1213
/**
1314
* A service that provides methods to make JSON Patch requests.
@@ -26,4 +27,20 @@ export class SubmissionJsonPatchOperationsService extends JsonPatchOperationsSer
2627
super();
2728
}
2829

30+
/**
31+
* Return an instance for RestRequest class
32+
*
33+
* @param uuid
34+
* The request uuid
35+
* @param href
36+
* The request href
37+
* @param body
38+
* The request body
39+
* @return Object<PatchRequestDefinition>
40+
* instance of PatchRequestDefinition
41+
*/
42+
protected getRequestInstance(uuid: string, href: string, body?: any): SubmissionPatchRequest {
43+
return new this.patchRequestConstructor(uuid, new URLCombiner(href, '?embed=item').toString(), body);
44+
}
45+
2946
}

0 commit comments

Comments
 (0)