Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implemented user registration, sending email notifications, and api documentation #9

Merged
merged 15 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 69 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,76 @@
name: Ambianic Functions API CI Test
name: Ambianic Functions API CI Test

ivelin marked this conversation as resolved.
Show resolved Hide resolved
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on: [pull_request]
on:
# Trigger the workflow on push or pull request against main branch
push:
branches:
- main
pull_request:
branches:
- main

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Git checkout
uses: actions/checkout@v2

- name: Install Node JS ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install Newman dependency
run: npm install --prefix tests/postman/

- name: Run the API and Postman's tests
run: |
cd tests/postman/ && newman run *
env:
CI: true
- name: Install Node JS ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- uses: actions/checkout@v1
- name: Install application dependencies
run: npm install

- name: Generate OpenAPI specs+
run: npm run generate-swagger && ./scripts.sh cleanup

- name: Local function testing
run: npm run mock-server & sleep 10 && npm run test:postman
env:
FUNCTION_URL: http://127.0.0.1:4010

- name: Wait for successful preview deployment
if: ${{ github.event_name == 'pull_request' }}
uses: jakepartusch/wait-for-netlify-action@v1
id: get-netlify-url
with:
site_name: "ambianic-serverless"
max_timeout: 60

- name: Run tests against deployed preview
if: ${{ github.event_name == 'pull_request' }}
run: npm run test:postman
env:
FUNCTION_URL: http://127.0.0.1:4010

- name: Run OpenAPI Tests and generate Code Coverage
run: cd openapi-docs/ && npm install && npm run test

- name: Create a static API documentation page from openapi specs
run: npm run generate-docs

# run this step only if its a push to the main branch
- name: Publish static API documentation to Github Pages
if: ${{ github.event_name == 'push' }}
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
personal_token: ${{ secrets.REPOSITORY_ACCESS_TOKEN }}
publish_dir: ./docs

- name: Run the semantic-release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Code Coverage Report
uses: codecov/codecov-action@v1
with:
file: ./openapi-docs/coverage/coverage-final.json
fail_ci_if_error: true

- name: Checkout generated files
uses: actions/checkout@v1
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pids
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov
# # Coverage directory used by tools like istanbul
# coverage
# *.lcov

# nyc test coverage
.nyc_output
Expand Down Expand Up @@ -103,3 +103,4 @@ dist
# TernJS port file
.tern-port
.env
.idea
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
# Ambianic-subscriptions

## Repo for ambianic premium subscription management

<p> This repo hosts [Netlify functions](https://www.netlify.com/products/functions/) that handle Ambianic premium user subscriptions. This is code that cannot run in the browser PWA, because it needs access keys to subscription and payment gateway services (Stripe) shared between all app users. If the code runs in the PWA, users will be able to see and manipulate each other's premium subscription data </p>


The image below shows the architecture of these serverless functions in connection with the Ambianic [PWA](https://github.com/ambianic/ambianic-ui/).
![serverless-functions-architecture](./assets/serverless-architecture.png)


## Running Locally

The serverless functions within this project are managed using [netlify-dev](https://www.netlify.com/products/dev/). Start the functions emulator from the `netlify` directory using `yarn netlify-dev` to listen for requests to any of created functions on port `5050`.

Credentials within this project are managed using environment variables and [GitHub Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets). To run the functions here locally using the `netlify dev` command, create a `.env` file in the root directory with the following values;

```
# Access key from Stripe to access your Stripe resources
STRIPE_KEY=STRIPE_KEY

# The product ID which users are subscribed to.
EMAIL_PRODUCT_ID=STRIPE_KEY
```

## CI / CD Pipeline


vickywane marked this conversation as resolved.
Show resolved Hide resolved
The three currently available serverless function endpoints are all tested using [Postman Tests](https://www.postman.com/automated-testing/). The API documentation explaining the endpoints can be found in the GitHub pages for this repository [here](https://ambianic.github.io/ambianic-subscriptions.github.io/). An exported file of the postman collection in json format is available at `./tests/postman/ambianic-functions-collection.postman_collection.json`.

Continuous integration for this project is managed using [GitHub Actions](https://github.com/features/actions), driven using the steps in the `.github/workflows/ci.yaml` file. The following sensitive credentials used within the CI jobs are managed using [Github Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets);

- STRIPE_KEY
- GITHUB_TOKEN
- NPM_TOKEN
- REPOSITORY_ACCESS_TOKEN
Loading