Abstracts the connection to and testing of soap services.
-
/.vscode/- Configuration for Visual Studio Code -
/build/- Build scripts and other assets needed for building. -
/dist/- Distributable files - static and generated by the build process. -
/doc/- Documentation; technical details and the output of any generated documentation -
/samples/- Samples that demonstrate the use of the package -
/spec/- Specifications; feature files, specialised specs such as load testing. Also any scripts needed for executing the specs. -
/src/- The source code, including unit tests -
/temp/- Temporary files that are discardable. (Not checked in to source control) -
/tools/- Executable binaries and other scripts -
/vendor/- Third-party executable binaries and other scripts
-
/.editorconfig- Standardised IDE configuration using EditorConfig -
/.gitignore- Filename patterns for Git to ignore -
/bitbucket-pipelines.yml- Configuration for BitBucket pipelines CI -
/CHANGELOG.md- Log of significant changes per release -
/mocha.opts- Configuration for the Mocha test runner -
/package.json- NPM package configuration -
/README.md- Entry point to the repository’s documentation (this file) -
/tslint.json- Typescript Lint configuration
npm install
export interface GetWeather {
country: string;
}
export interface GetWeatherResult {
isSunny: boolean;
}
export interface ServiceClient extends SoapClient {
GetWeather: SoapMethod<GetWeather, GetWeatherResult>;
}
const config: ConnectionConfig = {
credentials: {
password: "password123",
user: "weatherman",
},
serviceUrl: "www.weatherforecast.com/api/weather",
wsdlUrl: "www.weatherforecast.com/api/weather?wsdl",
};
Connections are transient and live only for the life of the call to the Soap Service.
const result = await execute<ServiceClient, GetWeather, GetWeatherResult>(
config, (c: ServiceClient) => {
return c.GetWeather;
}, {
country: "Australia",
});
console.log(`Australia is sunny: ${result.isSunny}`);
// Calling server.initialise before all tests runs sets up the test Mock Server:
// - The server will be refreshed before each test, where the supplied resetService function is called
// - The server will be stopped upon completion of all tests
// Create stub to represent fake call (see fakeGetWeather definition below)
export const getWeather: SinonStub = stub();
const server: MockServer = new MockServer({
resetService: reset,
serviceDefinition: {
Weather: {
WeatherSoap: {
GetWeather: getWeather,
},
},
},
serviceUrlPath: "/api/weather", // URL path to the service
wsdl: readFileSync(join(__dirname, "service.wsdl"), "utf8"), // Supply a copy of the wsdl
wsdlUrlPath: "/api/weather", // URL path to the WSDL (this can be different to the serviceUrlPath)
});
BeforeAll(() => server.initialise());
export function reset() {
getWeather.reset();
getWeather.callsFake(fakeGetWeather);
}
function fakeGetWeather(): { GetWeatherResult: boolean } {
return { GetWeatherResult: true };
}
// Call getStatus on MockServer object
const status: MockServerStatus = server.getStatus();
/*
MockServerStatus {
config: {
credentials: {
password: string;
user: string;
},
serviceUrl: string;
wsdlUrl: string;
};
isAvailable: boolean;
}
*/
// Call suspendService on the MockServer object, specifying the temporary timeout for the client (milliseconds)
server.suspendService(100);