-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Simulations): Add simulation run events resources
- Loading branch information
1 parent
56102d7
commit 832cc89
Showing
29 changed files
with
363 additions
and
46 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/__tests__/mocks/resources/simulation-run-events.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
import { ISimulationRunEventResponse } from '../../../types'; | ||
import { Response, ResponsePaginated } from '../../../internal'; | ||
|
||
export const SimulationRunEventMock: ISimulationRunEventResponse = { | ||
id: 'ntfsimevt_123', | ||
status: 'success', | ||
event_type: 'subscription.created', | ||
payload: {}, | ||
request: null, | ||
response: null, | ||
created_at: '2024-09-18T12:24:47.960617Z', | ||
updated_at: '2024-09-18T12:24:48.309530Z', | ||
}; | ||
|
||
export const SimulationRunEventMockResponse: Response<ISimulationRunEventResponse> = { | ||
data: SimulationRunEventMock, | ||
meta: { | ||
request_id: '', | ||
}, | ||
}; | ||
|
||
export const ListSimulationRunEventMockResponse: ResponsePaginated<ISimulationRunEventResponse> = { | ||
data: [SimulationRunEventMock], | ||
meta: { | ||
request_id: '', | ||
pagination: { | ||
estimated_total: 10, | ||
has_more: true, | ||
next: '/simulations/ntfsim_123/runs/ntfsimrun_123/events?after=1', | ||
per_page: 10, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
import { SimulationRunEventsResource, type ListSimulationRunEventsQueryParameters } from '../../resources'; | ||
import { getPaddleTestClient } from '../helpers/test-client'; | ||
import { | ||
SimulationRunEventMockResponse, | ||
SimulationRunEventMock, | ||
ListSimulationRunEventMockResponse, | ||
} from '../mocks/resources/simulation-run-events.mock'; | ||
import { QueryParameters } from '../../internal/base'; | ||
|
||
const simulationId = 'ntfsim_123'; | ||
const simulationRunId = 'ntfsimrun_123'; | ||
const simulationRunEventId = 'ntfsimevent_123'; | ||
|
||
describe('SimulationRunEventsResource', () => { | ||
test('should return a list of simulationRunEvents', async () => { | ||
const paddleInstance = getPaddleTestClient(); | ||
paddleInstance.get = jest.fn().mockResolvedValue(ListSimulationRunEventMockResponse); | ||
|
||
const simulationRunEventsResource = new SimulationRunEventsResource(paddleInstance); | ||
const simulationRunEventCollection = simulationRunEventsResource.list(simulationId, simulationRunId); | ||
|
||
let simulationRunEvents = await simulationRunEventCollection.next(); | ||
expect(paddleInstance.get).toBeCalledWith(`/simulations/${simulationId}/runs/${simulationRunId}/events?`); | ||
expect(simulationRunEvents.length).toBe(1); | ||
|
||
simulationRunEvents = await simulationRunEventCollection.next(); | ||
expect(paddleInstance.get).toBeCalledWith(`/simulations/${simulationId}/runs/${simulationRunId}/events?after=1`); | ||
expect(simulationRunEvents.length).toBe(1); | ||
}); | ||
|
||
test('should accept query params and return a list of simulationRunEvents', async () => { | ||
const paddleInstance = getPaddleTestClient(); | ||
paddleInstance.get = jest.fn().mockResolvedValue(ListSimulationRunEventMockResponse); | ||
const simulationRunEventsResource = new SimulationRunEventsResource(paddleInstance); | ||
const queryParams: ListSimulationRunEventsQueryParameters = { | ||
after: '2', | ||
id: ['1234'], | ||
}; | ||
|
||
const simulationRunEventCollection = simulationRunEventsResource.list(simulationId, simulationRunId, queryParams); | ||
let simulationRunEvents = await simulationRunEventCollection.next(); | ||
|
||
expect(paddleInstance.get).toBeCalledWith( | ||
`/simulations/${simulationId}/runs/${simulationRunId}/events?after=2&id=1234`, | ||
); | ||
expect(simulationRunEvents.length).toBe(1); | ||
}); | ||
|
||
test('should return a single simulationRunEvent by ID', async () => { | ||
const simulationRunEventId = SimulationRunEventMock.id; | ||
const paddleInstance = getPaddleTestClient(); | ||
paddleInstance.get = jest.fn().mockResolvedValue(SimulationRunEventMockResponse); | ||
|
||
const simulationRunEventsResource = new SimulationRunEventsResource(paddleInstance); | ||
const simulationRunEvent = await simulationRunEventsResource.get( | ||
simulationId, | ||
simulationRunId, | ||
simulationRunEventId, | ||
); | ||
|
||
expect(paddleInstance.get).toBeCalledWith( | ||
`/simulations/${simulationId}/runs/${simulationRunId}/events/${simulationRunEventId}`, | ||
); | ||
expect(simulationRunEvent).toBeDefined(); | ||
expect(simulationRunEvent.id).toBe(simulationRunEventId); | ||
}); | ||
|
||
test('should replay an existing simulationRunEvent', async () => { | ||
const simulationRunEventId = SimulationRunEventMock.id; | ||
|
||
const paddleInstance = getPaddleTestClient(); | ||
paddleInstance.post = jest.fn().mockResolvedValue(SimulationRunEventMockResponse); | ||
|
||
const simulationRunEventsResource = new SimulationRunEventsResource(paddleInstance); | ||
const replayedSimulationRunEvent = await simulationRunEventsResource.replay( | ||
simulationId, | ||
simulationRunId, | ||
simulationRunEventId, | ||
); | ||
|
||
expect(paddleInstance.post).toBeCalledWith( | ||
`/simulations/${simulationId}/runs/${simulationRunId}/events/${simulationRunEventId}/replay`, | ||
undefined, | ||
); | ||
expect(replayedSimulationRunEvent).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
import { type ISimulationEventRequest } from '../../types'; | ||
|
||
export class SimulationEventRequest { | ||
public readonly body: string; | ||
|
||
constructor(simulationEventRequestResponse: ISimulationEventRequest) { | ||
this.body = simulationEventRequestResponse.body; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
import { type ISimulationEventResponse } from '../../types'; | ||
|
||
export class SimulationEventResponse { | ||
public readonly body: string; | ||
public readonly statusCode: number; | ||
|
||
constructor(simulationEventResponse: ISimulationEventResponse) { | ||
this.body = simulationEventResponse.body; | ||
this.statusCode = simulationEventResponse.status_code; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
export * from './simulation-run-event'; | ||
export * from './simulation-run-event-collection'; |
15 changes: 15 additions & 0 deletions
15
src/entities/simulation-run-event/simulation-run-event-collection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
import { SimulationRunEvent } from '../../entities'; | ||
import { type ISimulationRunEventResponse } from '../../types'; | ||
import { Collection } from '../../internal/base'; | ||
|
||
export class SimulationRunEventCollection extends Collection<ISimulationRunEventResponse, SimulationRunEvent> { | ||
override fromJson(data: ISimulationRunEventResponse): SimulationRunEvent { | ||
return new SimulationRunEvent(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/enums/simulation-run-event/simulation-run-event-status.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
export type SimulationRunEventStatus = 'pending' | 'success' | 'failed' | 'aborted'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
import { SimulationRunEvent, SimulationRunEventCollection } from '../../entities'; | ||
import { type ISimulationRunEventResponse } from '../../types'; | ||
import { type ErrorResponse, type Response } from '../../internal'; | ||
import { BaseResource, PathParameters, QueryParameters } from '../../internal/base'; | ||
import type { ListSimulationRunEventsQueryParameters } from './operations'; | ||
|
||
export * from './operations'; | ||
|
||
const SimulationRunEventPaths = { | ||
list: '/simulations/{simulation_id}/runs/{simulation_run_id}/events', | ||
get: '/simulations/{simulation_id}/runs/{simulation_run_id}/events/{simulation_event_id}', | ||
replay: '/simulations/{simulation_id}/runs/{simulation_run_id}/events/{simulation_event_id}/replay', | ||
} as const; | ||
|
||
export class SimulationRunEventsResource extends BaseResource { | ||
public list( | ||
simulationId: string, | ||
simulationRunId: string, | ||
queryParams?: ListSimulationRunEventsQueryParameters, | ||
): SimulationRunEventCollection { | ||
const queryParameters = new QueryParameters(queryParams); | ||
const urlWithPathParams = new PathParameters(SimulationRunEventPaths.list, { | ||
simulation_id: simulationId, | ||
simulation_run_id: simulationRunId, | ||
}).deriveUrl(); | ||
|
||
return new SimulationRunEventCollection(this.client, urlWithPathParams + queryParameters.toQueryString()); | ||
} | ||
|
||
public async get( | ||
simulationId: string, | ||
simulationRunId: string, | ||
simulationEventId: string, | ||
): Promise<SimulationRunEvent> { | ||
const urlWithPathParams = new PathParameters(SimulationRunEventPaths.get, { | ||
simulation_id: simulationId, | ||
simulation_run_id: simulationRunId, | ||
simulation_event_id: simulationEventId, | ||
}).deriveUrl(); | ||
|
||
const response = await this.client.get<undefined, Response<ISimulationRunEventResponse> | ErrorResponse>( | ||
urlWithPathParams, | ||
); | ||
|
||
const data = this.handleResponse<ISimulationRunEventResponse>(response); | ||
|
||
return new SimulationRunEvent(data); | ||
} | ||
|
||
public async replay( | ||
simulationId: string, | ||
simulationRunId: string, | ||
simulationEventId: string, | ||
): Promise<SimulationRunEvent> { | ||
const urlWithPathParams = new PathParameters(SimulationRunEventPaths.replay, { | ||
simulation_id: simulationId, | ||
simulation_run_id: simulationRunId, | ||
simulation_event_id: simulationEventId, | ||
}).deriveUrl(); | ||
|
||
const response = await this.client.post<undefined, Response<ISimulationRunEventResponse> | ErrorResponse>( | ||
urlWithPathParams, | ||
undefined, | ||
); | ||
|
||
const data = this.handleResponse<ISimulationRunEventResponse>(response); | ||
|
||
return new SimulationRunEvent(data); | ||
} | ||
} |
Oops, something went wrong.