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

Commit

Permalink
Merge pull request #29 from libero/add-mock-service
Browse files Browse the repository at this point in the history
feat: add mock server to development stack and configure for testing
  • Loading branch information
Cory authored Jul 19, 2021
2 parents 5e95c91 + abd77cb commit a450c77
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
32 changes: 32 additions & 0 deletions .mockServer/initializerJson.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"httpRequest": {
"method": "POST",
"path": "/pdf-generation/start",
"body": {}
},
"httpResponse": {
"body": "{\"status\": {\"code\": 200,\"message\": \"job created successfully\"},\"message\": {\"jobid\": \"4b111882-d0e8-4d3d-8ef2-043ac3751ea2\"}}",
"statusCode": 200
}
},
{
"httpRequest": {
"method": "POST",
"path": "/pdf-generation/status"
},
"httpResponse": {
"body": "{\"status\": { \"code\": 200, \"message\": { \"id\": \"385ae272-e98e-47d9-83f5-c3ded54ab467\", \"lastUpdatedTime\": 1620885422660, \"status\": \"completed\" }}}",
"statusCode": 200
}
},
{
"httpRequest": {
"method": "HEAD",
"path": "/articles/.*"
},
"httpResponse": {
"statusCode": 200
}
}
]
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ RUN npm install

COPY src/ src/

CMD ["npm", "run", "dev"]

#
# Stage: Production build
#
Expand Down
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
IMAGE_TAG ?= local

build:
docker build --no-cache -t editor-pdf-service:${IMAGE_TAG} .
IMAGE_TAG=${IMAGE_TAG} docker-compose build editor-pdf-service

start:
npm run build
npm start
RUN_ENV=prod ${MAKE} build
IMAGE_TAG=${IMAGE_TAG} docker-compose up -d

start_dev:
npm run dev
RUN_ENV=dev ${MAKE} build
IMAGE_TAG=${IMAGE_TAG} docker-compose up -d
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ make start_dev

By default the service should now be available at `http://localhost:4001` and any changes made to files within the `/dev` directory will be picked up and cause the service to restart.

When in dev mode the application relies on [`mockserver`](https://www.mock-server.com/) to provide mocked responses to external requests. These responses can be configured [here](.mockServer/initializerJson.json) to change expected behaviour.

## Configuration

The service can be configured through the use of environment variables.
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "3.9"
services:
mockServer:
image: mockserver/mockserver:mockserver-5.11.1
container_name: ${PREFIX-editor}-mock-service
ports:
- 1080:1080
environment:
MOCKSERVER_INITIALIZATION_JSON_PATH: /config/initializerJson.json
volumes:
- './.mockserver:/config:ro'
editor-pdf-service:
build:
context: './'
target: ${RUN_ENV:-prod}
image: ${PREFIX-editor}-pdf-service:${IMAGE_TAG:-local}
environment:
- ARTICLE_STORE_PATH=http://${PREFIX-editor}-mock-service:1080/articles/
- GENERATION_STATUS_URL=http://${PREFIX-editor}-mock-service:1080/pdf-generation/status
- GENERATION_START_URL=http://${PREFIX-editor}-service:1080/pdf-generation/start
ports:
- 4001:4001
volumes:
- ./src/:/app/src
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const app: express.Application = express();

// Log all requests on this route.
app.use(logRequest);

app.get('/health', (_, res) => res.sendStatus(200));
app.post('/generate/:articleId', async (req, res) => {
try {
Expand Down

0 comments on commit a450c77

Please sign in to comment.