{"id":22772307,"url":"https://github.com/pactflow/example-provider-js-sns","last_synced_at":"2025-04-15T06:47:50.662Z","repository":{"id":42568443,"uuid":"309289748","full_name":"pactflow/example-provider-js-sns","owner":"pactflow","description":"Example JS AWS SNS Provider","archived":false,"fork":false,"pushed_at":"2025-04-14T19:47:58.000Z","size":487,"stargazers_count":2,"open_issues_count":2,"forks_count":8,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-15T06:47:42.501Z","etag":null,"topics":["example"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pactflow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-11-02T07:25:40.000Z","updated_at":"2025-04-14T04:57:14.000Z","dependencies_parsed_at":"2024-10-19T12:04:08.841Z","dependency_job_id":"d51a5f1d-ed4f-4925-b21c-b6bc18978377","html_url":"https://github.com/pactflow/example-provider-js-sns","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-provider-js-sns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-provider-js-sns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-provider-js-sns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-provider-js-sns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pactflow","download_url":"https://codeload.github.com/pactflow/example-provider-js-sns/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249023707,"owners_count":21199958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example"],"created_at":"2024-12-11T17:08:03.197Z","updated_at":"2025-04-15T06:47:50.645Z","avatar_url":"https://github.com/pactflow.png","language":"JavaScript","readme":"# Example NodeJS SNS Provider\n\n[![Build Status](https://github.com/pactflow/example-provider-js-sns/actions/workflows/build.yml/badge.svg)](https://github.com/pactflow/example-provider-js-sns/actions)\n\n[![Can I deploy Status](https://test.pactflow.io/pacticipants/pactflow-example-provider-js-sns/branches/master/latest-version/can-i-deploy/to-environment/production/badge.svg)](https://test.pactflow.io/pacticipants/pactflow-example-provider-js-sns/branches/master/latest-version/can-i-deploy/to-environment/production/badge)\n\n[![Pact Status](https://test.pactflow.io/pacts/provider/pactflow-example-provider-js-sns/consumer/pactflow-example-consumer-js-sns/latest/badge.svg?label=provider)](https://test.pactflow.io/pacts/provider/pactflow-example-provider-js-sns/consumer/pactflow-example-consumer-js-sns/latest) (latest pact)\n\n[![Pact Status](https://test.pactflow.io/matrix/provider/pactflow-example-provider-js-sns/latest/master/consumer/pactflow-example-consumer-js-sns/latest/master/badge.svg?label=provider)](https://test.pactflow.io/pacts/provider/pactflow-example-provider-js-sns/consumer/pactflow-example-consumer-js-sns/latest/master) (prod/prod pact)\n\nThis is an example of a NodeJS provider that uses Pact, [PactFlow](https://pactflow.io) and GitHub Actions to ensure that it is compatible with the expectations its consumers have of it.\n\nIt is using a public tenant on PactFlow, which you can access [here](https://test.pactflow.io) using the credentials `dXfltyFMgNOFZAxr8io9wJ37iUpY42M`/`O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`. The latest version of the Example Consumer/Example Provider pact is published [here](https://test.pactflow.io/pacts/provider/pactflow-example-provider-js-sns/consumer/pactflow-example-consumer-js-sns/latest).\n\nIn the following diagram, we'll be testing the \"Product Update API\", a simple HTTP service that receives product updates via a REST API and publishes product events on the `product` topic.\n\nWe need to be able to test that we are able to produce valid events to the SNS topic that matches what the consumer(s) can handle:\n\n![SNS Architecture](docs/js-sns.png \"SNS Architecture\")\n\n## Theory\n\nModern distributed architectures are increasingly integrated in a decoupled, asynchronous fashion. Message queues such as ActiveMQ, RabbitMQ, SNS, SQS, Kafka and Kinesis are common, often integrated via small and frequent numbers of microservices (e.g. lambda).\n\nPact supports these use cases, by abstracting away the _protocol_ and focussing on the messages passing between them.\n\nTo reiterate: Pact does not know about the various message queueing technologies - there are simply too many! And more importantly, Pact is really about testing the _messages_ that pass between them, you can still write your standard _functional_ tests using other frameworks designed for such things.\n\nWhen writing tests, Pact takes the place of the intermediary (MQ/broker etc.) and confirms whether or not the consumer is able to _handle_ a given event, or that the provider will be able to _produce_ the correct message.\n\n### How to write tests?\n\nWe recommend that you split the code that is responsible for handling the protocol specific things - in this case the SNS publishing code - and the piece of code that actually *produces* payload.\n\nYou're probably familiar with layered architectures such as Ports and Adaptors (also referred to as a Hexagonal architecture). Following a modular architecture will allow you to do this much more easily:\n\n![Code Modularity](docs/ports-and-adapters.png \"Code Modularity\")\n\nThis code base is setup with this modularity in mind (key files):\n\n* [REST API](server.js)\n* [Event Service (SNS Producer)](src/product/product.event.service.js)\n* Business Logic\n   * [Product](src/product/product.js)\n   * [Event Producer](src/product/product.event.js)\n\nThe target of our [provider pact test](src/product/product.pact.test.js) is the [Event Producer](src/product/product.event.js), which is responsible for producing a Product update event, that the Event Service will publish to SNS.\n\nSee also:\n\n* https://dius.com.au/2017/09/22/contract-testing-serverless-and-asynchronous-applications/\n* https://dius.com.au/2018/10/01/contract-testing-serverless-and-asynchronous-applications---part-2/\n\n## Pre-requisites\n\n**Software**:\n\n* [AWS SAM](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-mac.html)\n*  https://docs.pactflow.io/docs/workshops/ci-cd/set-up-ci/prerequisites/\n\n## Usage\n\nSee also the [PactFlow CI/CD Workshop](https://github.com/pactflow/ci-cd-workshop) for more background.\n\n### Testing\n* Run the Pact tests: `make test`\n \n### Running  locally\n\n* Start the Provider API (with a local SNS setup with localstack): `make start`\n* Create a product: `make create-product`\n* Update a product: `make update-product`\n* Delete a product: `make delete-product`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpactflow%2Fexample-provider-js-sns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpactflow%2Fexample-provider-js-sns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpactflow%2Fexample-provider-js-sns/lists"}