Skip to content

DariuszWietecha/node-sqs-soap-nmbrsapi-workflow

Repository files navigation

Node SQS SOAP Nmbrs.nl API workflow

Introduction

Workflow is triggered by SQS messages. During the execution, it retrieves an employee absence data from api.nmbrs.nl API and saves as JSON files with the required structure.

Implementation details

Main used dependencies:

During the implemented was used node v10.16.3. v10.12.0 version of node is required because fs.mkdir with options.recursive = true was used.

Running the workflow

  1. Install dependencies and build using npm install.
  2. Copy example.env as .env and update it according to a queue details which will be used to trigger the workflow.
  3. Run the workflow using npm start.
  4. Send message to the queue.
  5. Check logs and an ./output directory.
  6. The workflow can be stopped by Ctrl + z(Windows).
  7. To re-build the workflow use npm run build.

Testing

Unit tests

  1. Run the Mocha by npm test.

Using SQS on Local Stack and Nmbrs.nl API

  1. Copy example.env as .env.
  2. Install Docker Compose, run the Docker and update .env/SQS_URL with Docker default machine IP:4576, e.g. SQS_URL=http://localhost:4576
  3. Run the Local Stack and create a queue by command npm run startLocalStack.
  4. Uncomment below two lines in src/index.ts:
// const messageCommand = "{'source_app' => 'nmbrs', 'user' => 'michiel.crommelinck@officient.io', 'pass' => '2ed523df992646bf9bcfef66f75ef758', 'group' => 1234, 'controller' => 'importDaysoff',}";
// lib.sendMessage(sqs, queueUrl, messageCommand);
  1. Build the workflow by command npm run build.
  2. Run workflow by command npm start.
  3. Check logs and an ./output folder.
  4. The workflow can be stopped by Ctrl + z(Windows).
  5. To restore workflow to normal state revert changes from point 4 and re-build the code(point 5).

Notes

  • .vscode directory was committed to the repository to let to debug the workflow execution and unit tests execution in VSCode.
  • Unit test contain assertions strictly testing the correctnes of data generated by the workflow.
  • Assertion for IEmployeData.historical_days_off[item].date compares parsed Date to solve timezones difference problem.
  • Unit tests related to error handling was skipped due to time limits.

About

Node microservice that consumes SQS messages, retrieves data from api.nmbrs.nl API and saves it as JSON files with the required structure.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published