Skip to content
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
92 changes: 50 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,13 @@ on:

jobs:

api:
name: API Build & Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: api

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
cache-dependency-path: api/yarn.lock # Specify the path to your yarn.lock

- name: Install Dependencies (API)
working-directory: api
run: yarn install --frozen-lockfile

#- name: Lint API
# run: npm run lint

- name: Create .env file
run: |
cp .env-dev .env
working-directory: api # Ensure it is created inside `api/`

- name: Run Tests (API)
run: yarn test

- name: Build API
run: yarn build

# Webapp (Next.js) Build & Test
webapp:
name: Webapp Build & Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: webapp
run:
working-directory: webapp

steps:
- name: Checkout Repository
Expand All @@ -65,14 +29,17 @@ jobs:
cache: yarn
cache-dependency-path: webapp/yarn.lock # Specify the path to your yarn.lock

- name: Install Dependencies (Webapp)
- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Lint Webapp
run: yarn lint

- name: Run Tests (Webapp)
run: npm test
- name: Run Tests
run: yarn test

- name: Run Contract Testings
run: yarn test:contract

- name: Restore cache Next.js build
uses: actions/cache@v3
Expand All @@ -84,7 +51,7 @@ jobs:
${{ runner.os }}-nextjs-

- name: Build Webapp
run: |
run: |
yarn build
ls -la

Expand All @@ -94,6 +61,47 @@ jobs:
path: webapp/.next
key: ${{ runner.os }}-nextjs-${{ github.ref_name }}-${{ hashFiles('webapp/yarn.lock') }}


api:
name: API Build & Test
runs-on: ubuntu-latest
needs: webapp
defaults:
run:
working-directory: api

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
cache-dependency-path: api/yarn.lock # Specify the path to your yarn.lock

- name: Install Dependencies
working-directory: api
run: yarn install --frozen-lockfile

#- name: Lint API
# run: npm run lint

- name: Create .env file
run: |
cp .env-dev .env
working-directory: api # Ensure it is created inside `api/`

- name: Run Tests
run: yarn test

- name: Run Contract Testings
run: yarn test:contract

- name: Build API
run: yarn build

# Merge Blocker: Ensure Both Builds Pass
merge_guard:
name: Ensure All Jobs Passed
Expand Down
11 changes: 8 additions & 3 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test": "jest --testMatch '**/src/**/*.spec.ts'",
"test:contract": "jest --testMatch '**/test/pact/**/*.spec.ts'",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
Expand All @@ -34,6 +35,8 @@
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "10.0.0",
"@nestjs/testing": "10.0.0",
"@pact-foundation/pact": "13.2.0",
"@pact-foundation/pact-node": "10.18.0",
"@types/express": "5.0.0",
"@types/jest": "29.5.2",
"@types/node": "20.3.1",
Expand All @@ -59,8 +62,10 @@
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"rootDir": ".",
"testMatch": [
"**/?(*.)+(spec).ts"
],
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Body, Controller, Logger, Post } from '@nestjs/common';
import {
Body,
Controller,
HttpCode,
HttpStatus,
Logger,
Post,
} from '@nestjs/common';
import { CreateShortenUrlUsecase } from './create-shorten-url.usecase';
import { CreateShortenUrlDto } from './create-shorten-url.dto';

Expand All @@ -7,6 +14,7 @@ export class CreateShortenUrlController {
constructor(private readonly shortenUrlUsecase: CreateShortenUrlUsecase) {}

@Post()
@HttpCode(HttpStatus.CREATED)
async shortenUrl(
@Body() request: CreateShortenUrlDto,
): Promise<{ shortenedUrl: string }> {
Expand Down
36 changes: 36 additions & 0 deletions api/test/pact/provider-verification.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Verifier } from '@pact-foundation/pact';
import path from 'path';
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { AppModule } from '../../src/app.module';

let app: INestApplication;

beforeAll(async () => {
const moduleFixture = await Test.createTestingModule({
imports: [AppModule],
}).compile();

app = moduleFixture.createNestApplication();
await app.init();
await app.listen(3001);
});

afterAll(async () => {
await app.close();
});

describe('API consumers integration verification', () => {
it('validates the expectations of the webapp consumer', async () => {
await new Verifier({
provider: 'api',
providerBaseUrl: 'http://localhost:3001', // your Nest app
pactUrls: [
path.resolve(
__dirname,
'../../../webapp/__tests__/pact/pacts/webapp-backend-api.json',
),
],
}).verifyProvider();
});
});
1 change: 1 addition & 0 deletions api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"esModuleInterop": true,
"module": "commonjs",
"declaration": true,
"removeComments": true,
Expand Down
Loading
Loading