salesforce-service is a wrapper that helps interacting with Salesforce REST and SOAP API easier. This can be very helpful while testing Salesforce application.
npm install --save-dev salesforce-service
Configuration file is a json file in which you can store all relevant information for your Salesforce application. Here is a example:
{
"urls":{
"testUrl": "https://test.salesforce.com",
"baseUrl": "https://test.salesforce.com",
"domain": "your-domain.my.salesforce.com"
},
"paths": {
"soap": "/services/Soap/u/51.0",
"data": "/services/data/v51.0",
"query": "/services/data/v51.0/query/?q="
}
}
const SfService = require('salesforce-service').SfService;
const service = new SfService({
configFile: 'config.json'
})
service.getSessionId({
username: 'youruser',
password: 'yourpass',
token:'yourtoken'
}).then((res) => {
console.log(res)
})
await service.query('your query command');
it('get record successfully', async () => {
const response = await service.getRecord('123');
expect(response.data).toEqual('got record');
});
it('create record successfully', async () => {
const data: JSON = JSON.parse('{"field1": "value1"}');
const response = await service.createRecord('name', data);
expect(response.data).toEqual('created record');
});
it('update record successfully', async () => {
const data: JSON = JSON.parse('{"field1": "value1"}');
const response = await service.updateRecord('123', data);
expect(response.data).toEqual('updated record');
});
it('delete record successfully', async () => {
const response = await service.deleteRecord('123');
expect(response.data).toEqual('deleted record');
});