uttpal / tc-connect-notifications

Connect Notifications biz layer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tc-connect-notifications

Connect Notifications biz layer

Pre-requisites

  • RabbitMQ
  • Node.JS 6+

Configuration

To override default settings please add them to a file ./config/local.js:

  • LOG_LEVEL: the log level (e.g. debug, info)
  • RABBITMQ_URL: the event RabbitMQ's URL
  • SOURCE_RABBIT_EXCHANGE_NAME: the event RabbitMQ's topic exchange name
  • SOURCE_RABBIT_QUEUE_NAME: the event RabbitMQ's queue name
  • COPILOT_TARGET_RABBIT_QUEUE_NAME: copilot slack queue
  • MANAGER_TARGET_RABBIT_QUEUE_NAME: manager slack queue routing key
  • DELAY_RABBIT_EXCHANGE_NAME: Exchange name used for delayed messages
  • UNCLAIMED_PROJECT_REPOST_DELAY: Amount of delay before reposting unclaimed project
  • TARGET_RABBIT_EXCHANGE_NAME: the notification RabbitMQ's topic exchange name
  • TARGET_RABBIT_QUEUE_NAME: the notification RabbitMQ's queue name
  • LOGENTRIES_TOKEN: the Logentries token generated from https://logentries.com/
  • API_BASE_URL: the base url to the API server to get project/user info
  • DISABLE_DELAY_EXCHANGE: Disable exchage type delay and use 'direct' instead(Note: after changing this delete existing delay exchange )
  • SLACK_ICON_URL: slack webhook icon url
  • SLACK_USERNAME: slack webhook username

Local Development using Docker (recommended)

Local Development

  • Install dependencies:

    cd tc-connect-notifications
    npm i
  • Start mock API server:

    npm i -g json-server
    cd local/mockServices
    json-server -p 3001 services.json
  • Start the app:

    cd tc-connect-notifications
    node app

Verification

  • Run lint

    npm run lint
  • Run tests

    npm run test
  • Generate coverage report

    npm run coverage

Manual verification

  • Start the app

  • Publish the following message to the source RabbitMQ via command line or GUI:

    • Exchange name: as configured SOURCE_RABBIT_EXCHANGE_NAME variable (e.g. projects)

    • Routing key: project.draft-created

    • Properties: correlation_id = 1000, content_type = application/json

    • Payload:

    {
      "id": 521,
      "directProjectId": 10591,
      "billingAccountId": null,
      "name": "test",
      "description": "test",
      "external": null,
      "bookmarks": [],
      "estimatedPrice": null,
      "actualPrice": null,
      "terms": [],
      "type": "visual_design",
      "status": "draft",
      "details": {
        "devices": [
          "phone"
        ],
        "utm": {}
      },
      "challengeEligibility": [],
      "createdAt": "2016-11-04T03:57:57.000Z",
      "updatedAt": "2016-11-04T03:57:57.000Z",
      "createdBy": 40152856,
      "updatedBy": 40152856,
      "members": [
        {
          "id": 1185,
          "userId": 40051331,
          "role": "manager",
          "isPrimary": true,
          "createdAt": "2016-11-04T03:57:57.000Z",
          "updatedAt": "2016-11-04T03:57:57.000Z",
          "createdBy": 40152856,
          "updatedBy": 40152856,
          "projectId": 521
        },
        {
          "id": 1189,
          "userId": 50051333,
          "role": "customer",
          "isPrimary": true,
          "createdAt": "2016-11-04T17:30:42.000Z",
          "updatedAt": "2016-11-04T17:30:42.000Z",
          "createdBy": 8547899,
          "updatedBy": 8547899,
          "projectId": 521
        }
      ],
      "attachments": []
    }
  • Verify that a notification message is sent to the target RabbitMQ TARGET_RABBIT_QUEUE_NAME

    {
      "recipients":[
        {
          "id":50051333,
          "params":{
            "projectId":521,
            "projectName":"test",
            "projectDescription":"test"
          }
        }
      ],
      "notificationType":"Project.Created",
      "subject":"Created"
    }

Delay verification

  • Publish the following message to the source RabbitMQ via command line or GUI:

    • Exchange name: as configured SOURCE_RABBIT_EXCHANGE_NAME variable (e.g. projects)

    • Routing key: project.updated

    • Properties: correlation_id = 1000, content_type = application/json

    • Payload:

    {
      "original": {
        "id": 1,
        "directProjectId": 10591,
        "billingAccountId": null,
        "name": "test",
        "description": "test",
        "external": null,
        "bookmarks": [],
        "estimatedPrice": null,
        "actualPrice": null,
        "terms": [],
        "type": "visual_design",
        "status": "in_review",
        "details": {
          "devices": [
            "phone"
          ],
          "utm": {}
        },
        "challengeEligibility": [],
        "createdAt": "2016-11-04T03:57:57.000Z",
        "updatedAt": "2016-11-04T03:57:57.000Z",
        "createdBy": 40152856,
        "updatedBy": 40152856,
        "members": [
          {
            "id": 1185,
            "userId": 40152856,
            "role": "manager",
            "isPrimary": true,
            "createdAt": "2016-11-04T03:57:57.000Z",
            "updatedAt": "2016-11-04T03:57:57.000Z",
            "createdBy": 40152856,
            "updatedBy": 40152856,
            "projectId": 521
          },
          {
            "id": 1189,
            "userId": 8547899,
            "role": "customer",
            "isPrimary": false,
            "createdAt": "2016-11-04T17:30:42.000Z",
            "updatedAt": "2016-11-04T17:30:42.000Z",
            "createdBy": 8547899,
            "updatedBy": 8547899,
            "projectId": 521
          }
        ],
        "attachments": []
      },
      "updated": {
        "id": 1,
        "directProjectId": 10591,
        "billingAccountId": null,
        "name": "test",
        "description": "test",
        "external": null,
        "bookmarks": [],
        "estimatedPrice": null,
        "actualPrice": null,
        "terms": [],
        "type": "visual_design",
        "status": "reviewed",
        "details": {
          "devices": [
            "phone"
          ],
          "utm": {}
        },
        "challengeEligibility": [],
        "createdAt": "2016-11-04T03:57:57.000Z",
        "updatedAt": "2016-11-05T00:00:00.000Z",
        "createdBy": 40152856,
        "updatedBy": 40152856,
        "members": [
          {
            "id": 1185,
            "userId": 40152856,
            "role": "manager",
            "isPrimary": true,
            "createdAt": "2016-11-04T03:57:57.000Z",
            "updatedAt": "2016-11-04T03:57:57.000Z",
            "createdBy": 40152856,
            "updatedBy": 40152856,
            "projectId": 1
          },
          {
            "id": 1189,
            "userId": 8547899,
            "role": "customer",
            "isPrimary": false,
            "createdAt": "2016-11-04T17:30:42.000Z",
            "updatedAt": "2016-11-04T17:30:42.000Z",
            "createdBy": 8547899,
            "updatedBy": 8547899,
            "projectId": 1
          },
          {
            "id": 1190,
            "userId": 8547900,
            "role": "customer",
            "isPrimary": true,
            "createdAt": "2016-11-04T17:30:42.000Z",
            "updatedAt": "2016-11-04T17:30:42.000Z",
            "createdBy": 8547899,
            "updatedBy": 8547899,
            "projectId": 1
          },
          {
            "id": 1190,
            "userId": 123456,
            "role": "customer",
            "isPrimary": false,
            "createdAt": "2016-11-04T17:30:42.000Z",
            "updatedAt": "2016-11-04T17:30:42.000Z",
            "createdBy": 8547899,
            "updatedBy": 8547899,
            "projectId": 1
          }
        ],
        "attachments": []
      }
    }
  • Verify that a slack notification in COPILOT_TARGET_RABBIT_QUEUE_NAME and one another after UNCLAIMED_PROJECT_REPOST_DELAY notifications continues coming until copilot is assigned.

{
  "username": "webhookbot",
  "icon_url": "https://emoji.slack-edge.com/T03R80JP7/topcoder/7c68acd90a6b6d77.png",
  "attachments": [
    {
      "fallback": "New Project: https://connect.topcoder.com/projects/| test",
      "pretext": "New Project: https://connect.topcoder.com/projects/| test",
      "fields": [
        {
          "title": "Description",
          "value": "test",
          "short": true
        },
        {
          "title": "Description",
          "value": "test",
          "short": false
        },
        {
          "title": "Ref Code",
          "value": 1,
          "short": false
        }
      ]
    }
  ]
}

About

Connect Notifications biz layer


Languages

Language:JavaScript 95.4%Language:Shell 4.6%