Assuming we have a main service we would like to test and some mock OData connection called RemoteService - testing it is surprisingly trivial.
First, create both a `remote-service.js` and `remote-service.cds` in some directory - I chose `srv/external/RemoteService`. Apart from the file extensions, the names are the same for both files.
In the `remote-service.cds`, you can define a simple action to communicate with the remote service. Don't forget to also implement the respective event handler in the `remote-service.js`.
```js
service RemoteService {
function sayHello(messages: array of String) returns array of String;
}
```
Next, in the `package.json`, you have to add the following reference. Remember to use the path to the file without the extension.
```json
"cds": {
"requires": {
"RemoteService": {
"kind": "odata",
"model": "./srv/external/RemoteService/remote-service"
}
}
}
```
Finally, in the implementation of your main service, all you have to do is the following:
```js
const externalService = await cds.connect.to('RemoteService');
let response = await externalService.sayHello(["abc", "def"]);
```
Now all you have to do is call `cds watch` and Bob's your uncle!