Skip to content

Commit

Permalink
NAS-128635: Experimenting with immutability
Browse files Browse the repository at this point in the history
  • Loading branch information
undsoft committed Apr 29, 2024
1 parent 41a2e7c commit 6df46b3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/app/core/testing/classes/mock-websocket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ export class MockWebSocketService extends WebSocketService {

mockCall<K extends ApiCallMethod>(method: K, response: CallResponseOrFactory<K>): void {
const mockedImplementation = (_: K, params: ApiCallParams<K>): Observable<unknown> => {
let preparedResponse = response;
if (response instanceof Function) {
return of(response(params));
preparedResponse = response(params);
}

return of(response);
Object.freeze(preparedResponse);

return of(preparedResponse);
};

when(this.call).calledWith(method).mockImplementation(mockedImplementation);
Expand Down Expand Up @@ -107,10 +110,13 @@ export class MockWebSocketService extends WebSocketService {
job = response;
}

return {
job = {
...job,
id: this.jobIdCounter,
} as Job<ApiJobResponse<M>>;
};

Object.freeze(job);
return job as Job<ApiJobResponse<M>>;
};
when(this.startJob).calledWith(method).mockReturnValue(of(this.jobIdCounter));
when(this.startJob).calledWith(method, anyArgument).mockReturnValue(of(this.jobIdCounter));
Expand Down

0 comments on commit 6df46b3

Please sign in to comment.