Skip to content

Commit

Permalink
Merge pull request #5 from openfoodfacts:makefile
Browse files Browse the repository at this point in the history
Makefile and set ports for testing
  • Loading branch information
john-gom authored Sep 18, 2023
2 parents 2fde972 + af0dde8 commit 52bdb79
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ COMPOSE_FILE=docker-compose.yml;docker/dev.yml
COMPOSE_PROJECT_NAME=off-query
COMPOSE_PATH_SEPARATOR=;
TAG=latest
QUERY_PORT=127.0.0.1:5511
POSTGRES_HOST=localhost
POSTGRES_PORT=5512
POSTGRES_PORT=127.0.0.1:5512
POSTGRES_DB=query
POSTGRES_USER=productopener
POSTGRES_PASSWORD=productopener
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Use this to start both the query service and associated database in Docker
up:
docker-compose up -d --build

# This task starts a Postgres database in Docker and then prepares the local environment for development
dev:
docker-compose up -d query_postgres
npm install
npm run migration:up

tests:
npm test

lint:
npm run lint
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To get started...
Run the following:

```
docker-compose up -d --build
docker-compose up -d query_postgres
```

### Use an existing Postgres database
Expand All @@ -28,7 +28,6 @@ Run the following:

```
npm install
npm run build
npm run migration:up
```

Expand Down Expand Up @@ -94,6 +93,4 @@ The "count" and "aggregate" POST endpoints accept a MongoDB style filter and agg

# TODO

- Run tests on PR
- Add branch protection
- Configure production deployment
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ services:
- POSTGRES_USER
- POSTGRES_PASSWORD
- MONGO_URI
# Use a different number so does not clash with locally running instance
ports:
- "${QUERY_PORT:-5511}:5510"
depends_on:
query_postgres:
condition: service_started
Expand Down
6 changes: 1 addition & 5 deletions docker/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
query_postgres:
# Expose port locally for testing purposes.
ports:
- 5512:5432
- "${POSTGRES_PORT:-5512}:5432"
volumes:
- ./data:/mnt/data
networks:
Expand All @@ -14,10 +14,6 @@ services:
environment:
# Use Product Opener's MongoDB
- MONGO_URI=mongodb://mongodb:27017
# Expose port locally for testing purposes.
# Use a different number so does not clash with locally running instance
ports:
- 5511:5510
volumes:
- ./data:/data
networks:
Expand Down
9 changes: 8 additions & 1 deletion src/health/health.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { HealthController } from './health.controller';
import { createTestingModule } from '../../test/test.helper';
import { AppModule } from '../app.module';
import { MongodbHealthIndicator } from './mongodb-health-indicator';
import { HealthCheckError, HealthIndicatorResult } from '@nestjs/terminus';
import {
HealthCheckError,
HealthIndicatorResult,
HealthCheckService,
} from '@nestjs/terminus';
import { ServiceUnavailableException } from '@nestjs/common';

describe('HealthController', () => {
Expand All @@ -27,6 +31,8 @@ describe('HealthController', () => {
it('should return unhealthy if mongodb is down', async () => {
await createTestingModule([AppModule], async (app) => {
const controller = app.get(HealthController);
const errorLog = (app.get(HealthCheckService)['logger'].error =
jest.fn());

const mongoIndicator = app.get(MongodbHealthIndicator);
mongoIndicator.isHealthy = jest.fn(async () => {
Expand All @@ -42,6 +48,7 @@ describe('HealthController', () => {
} catch (e) {
expect(e).toBeInstanceOf(ServiceUnavailableException);
expect(e.response.status).toBe('error');
expect(errorLog).toHaveBeenCalledTimes(1);
}
});
});
Expand Down

0 comments on commit 52bdb79

Please sign in to comment.