Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #14 from tamedia-pmd/develop
Browse files Browse the repository at this point in the history
Merge changes from develop to master for prod release
  • Loading branch information
LukeZzzHD authored Oct 14, 2021
2 parents 00f8ce7 + ce60af0 commit 353fb39
Show file tree
Hide file tree
Showing 27 changed files with 13,122 additions and 1,066 deletions.
116 changes: 116 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
version: 2.1

jobs:
build:
docker:
# circleci node image version
- image: circleci/node:12

steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package-lock.json" }}

- run:
name: Install Dependencies
command: npm install

- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package-lock.json" }}

- run:
name: Build floors
command: npm run build

- run:
name: Run tests
command: npm test

- persist_to_workspace:
root: ~/project
paths:
- node_modules/
- config/
- package.json
deploy:
docker:
# circleci node image version
- image: circleci/node:12

environment:
BASH_ENV: bash_env

steps:
- checkout
- attach_workspace:
at: ~/project

- run:
name: Export Stage name into BASH_ENV
command: |
chmod u+x ~/project/.circleci/helpers/setStageName.sh
echo "export STAGE=`~/project/.circleci/helpers/setStageName.sh`" >> $BASH_ENV
- run:
name: Prepare deployment file
command: |
echo "deploying to $STAGE"
chmod u+x ~/project/.circleci/helpers/setEnvironmentVariables.sh
./.circleci/helpers/setEnvironmentVariables.sh
- run:
name: Set AWS credentials based on stage
command: |
echo "Setting $STAGE-credentials"
chmod u+x ~/project/.circleci/helpers/setAwsCredentials.sh
./.circleci/helpers/setAwsCredentials.sh
- run:
name: Deploy to AWS Lambda
command: |
if [ $STAGE == 'prod' ]
then
npm run deploy-prod
else
npm run deploy
fi
workflows:
version: 2
staging-build:
jobs:
- build:
name: build stage
filters:
branches:
only: /(^develop$)/
- deploy:
name: deploy stage
requires:
- build stage

un-tagged-build:
jobs:
- build:
filters:
tags:
ignore: /(^v.*)/
branches:
ignore: /(^develop$)/
tagged-build:
jobs:
- build:
name: build tag
filters:
branches:
ignore: /.*/
tags:
only: /^v.*/
- deploy:
name: deploy prod
filters:
tags:
only: /^v.*/
requires:
- build tag
7 changes: 7 additions & 0 deletions .circleci/helpers/setAwsCredentials.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -eu

case "$STAGE" in
"dev" ) ./node_modules/.bin/sls config credentials --provider aws --key $AWS_ACCESS_KEY_ID_DEV --secret $AWS_SECRET_ACCESS_KEY_DEV --overwrite && exit 0;;
"prod" ) ./node_modules/.bin/sls config credentials --provider aws --key $AWS_ACCESS_KEY_ID_PROD --secret $AWS_SECRET_ACCESS_KEY_PROD --overwrite && exit 0;;
esac
14 changes: 14 additions & 0 deletions .circleci/helpers/setEnvironmentVariables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -eu

cd ~/project/config

sed -i "s~###SLACK_SIGNING_SECRET###~${SLACK_SIGNING_SECRET_DEV}~" config.dev.json
sed -i "s~###SLACK_VERIFICATION_TOKEN###~${SLACK_VERIFICATION_TOKEN_DEV}~" config.dev.json
sed -i "s~###SLACK_BOT_USER_OAUTH_ACCESS_TOKEN###~${SLACK_BOT_USER_OAUTH_ACCESS_TOKEN_DEV}~" config.dev.json


sed -i "s~###SLACK_SIGNING_SECRET###~${SLACK_SIGNING_SECRET_PROD}~" config.prod.json
sed -i "s~###SLACK_VERIFICATION_TOKEN###~${SLACK_VERIFICATION_TOKEN_PROD}~" config.prod.json
sed -i "s~###SLACK_BOT_USER_OAUTH_ACCESS_TOKEN###~${SLACK_BOT_USER_OAUTH_ACCESS_TOKEN_PROD}~" config.prod.json

13 changes: 13 additions & 0 deletions .circleci/helpers/setStageName.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -eu

STAGE=""

case "$CIRCLE_BRANCH" in
"master" ) echo "prod" && exit 0;;
"develop" ) echo "dev" && exit 0;;
esac
case "$CIRCLE_TAG" in
v* ) echo "prod" && exit 0;;
* ) echo "setStageNameError" && exit 1;;
esac
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ jspm_packages

coverage

config

yarn-error.log
103 changes: 58 additions & 45 deletions __tests__/api/locate.spec.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
const { locate } = require("../../api/locate");

const getRealBodyWithText = text => `"token=fZf6rkRHrkL9EpC3eUDUBi7Q&team_id=T8N20GRJT&team_domain=radiovisual&channel_id=DUJR38729&channel_name=directmessage&user_id=U8MRG1HUN&user_name=wuergler&command=%2Froom&text=${encodeURIComponent(text)}&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FT8N20GRJT%2F970853870197%2FyCriSk4EAdH9H0pTP0DrnVHD&trigger_id=970381596788.294068569639.e645670ddd8d9cd7bd13b00aa991e36f"`;
const getRealBodyWithText = (text) =>
`"token=fZf6rkRHrkL9EpC3eUDUBi7Q&team_id=T8N20GRJT&team_domain=radiovisual&channel_id=DUJR38729&channel_name=directmessage&user_id=U8MRG1HUN&user_name=wuergler&command=%2Froom&text=${encodeURIComponent(
text
)}&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FT8N20GRJT%2F970853870197%2FyCriSk4EAdH9H0pTP0DrnVHD&trigger_id=970381596788.294068569639.e645670ddd8d9cd7bd13b00aa991e36f"`;

describe("api.locate", () => {
test("should find valid rooms", async () => {
const event = {
body: getRealBodyWithText('boston')
};
test("should find valid rooms", async () => {
const event = {
body: getRealBodyWithText("boston"),
};

const actual = await locate(event);
expect(JSON.stringify(actual)).toContain('`Boston`');
});

test("returns the required payload", async () => {
const event = {
body: getRealBodyWithText('boston')
};
const actual = await locate(event);
expect(JSON.stringify(actual)).toContain("`Sitzungszimmer A5.1 Boston`");
});

const result = await locate(event);
expect(result.statusCode).toBe(200);
expect(result.headers['Content-Type']).toBe('application/json');
expect(result.body).toBeTruthy();
});

test("should report invalid rooms", async () => {
const event = {
body: getRealBodyWithText('noopRoom')
};
test("returns the required payload", async () => {
const event = {
body: getRealBodyWithText("boston"),
};

const actual = await locate(event);
const result = await locate(event);
expect(result.statusCode).toBe(200);
expect(result.headers["Content-Type"]).toBe("application/json");
expect(result.body).toBeTruthy();
});

expect(JSON.stringify(actual)).toContain('*0* rooms found for `noopRoom`');
});

test("should report invalid rooms", async () => {
const event = {
body: getRealBodyWithText("noopRoom"),
};

const actual = await locate(event);

expect(JSON.stringify(actual)).toContain(
"*0* rooms found for `noopRoom`"
);
});

/*
test("should report invalid rooms with empty data", async () => {
const event = {
body: ''
Expand All @@ -41,24 +47,31 @@ describe("api.locate", () => {
const actual = await locate(event);
expect(JSON.stringify(actual)).toContain('You need to enter a room name to search for. Try `/room paris`');
});

test("should find rooms with special characters provided", async () => {
const actual1 = await locate({
body: getRealBodyWithText('VR-Sitzungszimmer')
});
});
*/

const actual2 = await locate({
body: getRealBodyWithText('VR----Sitzungszimmer')
});

const actual3 = await locate({
body: getRealBodyWithText('VR:----&/+Sitzungszimmer')
});
test("should find rooms with special characters provided", async () => {
const actual1 = await locate({
body: getRealBodyWithText("VR-Sitzungszimmer"),
});

expect(JSON.stringify(actual1)).toContain('*1* room found for `VR-Sitzungszimmer`');
expect(JSON.stringify(actual2)).toContain('*1* room found for `VR----Sitzungszimmer`');
expect(JSON.stringify(actual3)).toContain('*1* room found for `VR:----&/+Sitzungszimmer`');
expect(JSON.stringify(actual3)).toContain('VR-Sitzungszimmer');
});
const actual2 = await locate({
body: getRealBodyWithText("VR----Sitzungszimmer"),
});

const actual3 = await locate({
body: getRealBodyWithText("VR:----&/+Sitzungszimmer"),
});

expect(JSON.stringify(actual1)).toContain(
"*1* room found for `VR-Sitzungszimmer`"
);
expect(JSON.stringify(actual2)).toContain(
"*1* room found for `VR----Sitzungszimmer`"
);
expect(JSON.stringify(actual3)).toContain(
"*1* room found for `VR:----&/+Sitzungszimmer`"
);
expect(JSON.stringify(actual3)).toContain("VR-Sitzungszimmer");
});
});
62 changes: 0 additions & 62 deletions __tests__/modules/responseBuilder.spec.js

This file was deleted.

Loading

0 comments on commit 353fb39

Please sign in to comment.