-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from Deltares/182-add-whatif-scenario-post-en…
…dpoint Add post what if endpoint
- Loading branch information
Showing
8 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
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,16 @@ | ||
export interface PostWhatIfScenarioFilter { | ||
whatIfTemplateId: string; | ||
name: string; | ||
|
||
/** | ||
* Since 2022.02. Properties can be included in the url. These will be used as | ||
* taskRunProperties, and override global or workflow properties. Each property has to be added | ||
* to the url seperately. Example: | ||
* | ||
* &property(fileName)=exportFile&property(outputValue)=9.0 | ||
* | ||
* Where the name of the property is fileName, the value is exportFile. The name of the second | ||
* property is outputValue, the value is 9.0. | ||
*/ | ||
properties?: { [key: string]: string | number } | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './whatIfTemplatesResponse.js' | ||
export * from './whatIfScenarioDescriptorsResponse.js' | ||
export * from './whatIfScenarioDescriptorResponse.js' |
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 @@ | ||
/* tslint:disable */ | ||
|
||
import { WhatIfScenarioDescriptor } from "./whatIfScenarioDescriptorsResponse"; | ||
|
||
/** | ||
* WhatIfScenarioResponse PI_JSON | ||
*/ | ||
export type PostWhatIfScenarioResponse = WhatIfScenarioDescriptor; |
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,51 @@ | ||
import { PiWebserviceProvider } from "../../../src/piWebserviceProvider"; | ||
import "cross-fetch/polyfill"; | ||
import expectedResponse from "../mock/whatifscenario.json"; | ||
import fetchMock from "fetch-mock"; | ||
import { PostWhatIfScenarioFilter } from "../../../src/requestParameters/postWhatIfScenarioFilter"; | ||
|
||
describe("postWhatIfScenario", function () { | ||
afterAll(function () { | ||
fetchMock.restore(); | ||
}); | ||
|
||
it("generates a valid postWhatIfScenario request", async function () { | ||
const baseUrl = | ||
"https://mock.dev/fewswebservices/rest/fewspiservice/v1/whatifscenario"; | ||
const queryParams = `whatIfTemplateId=testid&name=test&property(ADD_SURGE)=0.2&property(MULTIPLY_SURGE)=1.3`; | ||
|
||
const url = `${baseUrl}?${queryParams}`; | ||
|
||
fetchMock.post(url, { | ||
status: 200, | ||
body: expectedResponse, | ||
}); | ||
|
||
const provider = new PiWebserviceProvider( | ||
"https://mock.dev/fewswebservices" | ||
); | ||
|
||
const properties = { | ||
ADD_SURGE: 0.2, | ||
MULTIPLY_SURGE: 1.3, | ||
}; | ||
|
||
const filter: PostWhatIfScenarioFilter = { | ||
whatIfTemplateId: "testid", | ||
name: "test", | ||
properties, | ||
}; | ||
const results = await provider.postWhatIfScenario(filter, ""); | ||
expect(results).toStrictEqual(expectedResponse); | ||
expect(results.id).toBe("id1"); | ||
expect(results.name).toBe("triple_the_surge"); | ||
expect(results.whatIfTemplateId).toBe("whatif_surge"); | ||
expect(results.properties?.length).toBe(2); | ||
expect(results.properties?.[0].id).toBe("ADD_SURGE"); | ||
expect(results.properties?.[0].type).toBe("number"); | ||
expect(results.properties?.[0].value).toBe(0); | ||
expect(results.properties?.[1].id).toBe("MULTIPLY_SURGE"); | ||
expect(results.properties?.[1].type).toBe("number"); | ||
expect(results.properties?.[1].value).toBe(3); | ||
}); | ||
}); |
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,9 @@ | ||
{ | ||
"id": "id1", | ||
"name": "triple_the_surge", | ||
"whatIfTemplateId": "whatif_surge", | ||
"properties": [ | ||
{ "id": "ADD_SURGE", "type": "number", "value": 0 }, | ||
{ "id": "MULTIPLY_SURGE", "type": "number", "value": 3 } | ||
] | ||
} |