Skip to content

Commit

Permalink
fix: refactor stakeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
Kpoke committed Apr 15, 2022
1 parent 91117c1 commit d46c7ec
Show file tree
Hide file tree
Showing 15 changed files with 565 additions and 448 deletions.
31 changes: 15 additions & 16 deletions .github/workflows/treetracker-api-build-deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: Test
runs-on: ubuntu-latest
container: node:10.18-jessie

# Service containers to run with `container-job`
services:
# Label used to access the service container
Expand All @@ -29,7 +29,7 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5
if: |
!contains(github.event.head_commit.message, 'skip-ci')
steps:
Expand All @@ -50,49 +50,48 @@ jobs:
env:
DATABASE_URL: postgresql://postgres:postgres@postgres/postgres


release:
name: Release
needs: test
runs-on: ubuntu-latest
if: |
!contains(github.event.head_commit.message, 'skip-ci') &&
github.event_name == 'push' &&
github.repository == "Greenstand/${{ github.event.repository.name }}"
github.repository_owner == 'Greenstand'
steps:
- uses: actions/checkout@v2

- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: '16.x'

- name: npm clean install
run: npm ci
working-directory: ${{ env.project-directory }}

- run: npm i -g semantic-release @semantic-release/{git,exec,changelog}

- run: semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: get-npm-version
id: package-version
uses: martinbeentjes/npm-get-version-action@master

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build snapshot and push on merge
id: docker_build_release
uses: docker/build-push-action@v2
Expand All @@ -101,12 +100,12 @@ jobs:
file: ./Dockerfile
push: true
tags: greenstand/${{ github.event.repository.name }}:${{ steps.package-version.outputs.current-version }}

- id: export_bumped_version
run: |
export BUMPED_VERSION="${{ steps.package-version.outputs.current-version }}"
echo "::set-output name=bumped_version::${BUMPED_VERSION}"
outputs:
bumped_version: ${{ steps.export_bumped_version.outputs.bumped_version }}

Expand All @@ -117,7 +116,7 @@ jobs:
if: |
!contains(github.event.head_commit.message, 'skip-ci') &&
github.event_name == 'push' &&
github.repository == "Greenstand/${{ github.event.repository.name }}"
github.repository_owner == 'Greenstand'
steps:
- uses: actions/checkout@v2
- name: Install kustomize
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/treetracker-api-deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: Deploy latest to prod environment, requires approval
runs-on: ubuntu-latest
if: |
github.repository == "Greenstand/${{ github.event.repository.name }}"
github.repository_owner == 'Greenstand'
steps:
- uses: actions/checkout@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/treetracker-api-deploy-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: Deploy latest to test environment, requires approval
runs-on: ubuntu-latest
if: |
github.repository == "Greenstand/${{ github.event.repository.name }}"
github.repository_owner == 'Greenstand'
steps:
- uses: actions/checkout@v2
with:
Expand Down
22 changes: 18 additions & 4 deletions api-tests/stakeholder-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ const request = require('supertest');
const { expect } = require('chai');
const server = require('../server/app');
const stakeholderSeed = require('../database/seeds/11_story_stakeholder');
const knex = require('../database/connection');
const knex = require('../server/database/knex');

describe('Stakeholder API tests.', () => {
before(async () => {
await stakeholderSeed.seed(knex);
});

after(async () => {
await knex('stakeholder').del();
});

describe('Stakeholder GET', () => {
it(`Should raise validation error with error code 422 -- 'id' should be a uuid `, function (done) {
request(server)
Expand All @@ -34,7 +38,12 @@ describe('Stakeholder API tests.', () => {
.expect(200)
.end(function (err, res) {
if (err) return done(err);
expect(res.body).to.have.keys(['stakeholders', 'totalCount']);
expect(res.body).to.have.keys([
'stakeholders',
'totalCount',
'links',
'query',
]);
expect(res.body.totalCount).to.eq(1);
expect(res.body.stakeholders[0]).to.eql({
...stakeholderSeed.stakeholderOne,
Expand All @@ -54,8 +63,13 @@ describe('Stakeholder API tests.', () => {
.expect(200)
.end(function (err, res) {
if (err) return done(err);
expect(res.body).to.have.keys(['stakeholders', 'totalCount']);
expect(res.body.totalCount).to.be.greaterThanOrEqual(2);
expect(res.body).to.have.keys([
'stakeholders',
'totalCount',
'links',
'query',
]);
expect(res.body.totalCount).to.eql(2);
expect(res.body.stakeholders).to.have.length(res.body.totalCount);
return done();
});
Expand Down
6 changes: 5 additions & 1 deletion database/seeds/11_story_stakeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ const stakeholderThree = Object.freeze({
});

const seed = async function (knex) {
await knex('stakeholder').insert([stakeholderOne, stakeholderTwo]);
await knex('stakeholder').insert([
stakeholderOne,
stakeholderTwo,
stakeholderThree,
]);
};

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion server/models/Session.js → server/database/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*/

const knex = require('../database/knex');
const knex = require('./knex');

class Session {
constructor() {
Expand Down
Loading

0 comments on commit d46c7ec

Please sign in to comment.