Skip to content
28 changes: 3 additions & 25 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
types:
- opened
- synchronize
branches:
- main
- develop
Expand All @@ -20,6 +21,8 @@ jobs:
run:
working-directory: app

if: ${{ github.event.pull_request.base.ref != 'develop' || github.event.pull_request.head.ref != 'main' }}

steps:
- name: Check out code
uses: actions/checkout@v4
Expand All @@ -34,42 +37,17 @@ jobs:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Check commit prefix
id: check-commit
run: |
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "run-tests=false" >> $GITHUB_ENV
echo "run-lint=false" >> $GITHUB_ENV

if [[ "$COMMIT_MSG" == Merge* ]]; then
echo "Merge commit detected, skipping commit message convention check."
else
if echo "$COMMIT_MSG" | grep -qE '^(feat|fix|chore|refactor|test)\:'; then
echo "✅ Commit message follows convention."
echo "run-lint=true" >> $GITHUB_ENV
fi
if echo "$COMMIT_MSG" | grep -qE '^test\:'; then
echo "✅ Test commit detected."
echo "run-tests=true" >> $GITHUB_ENV
fi
fi

- name: Install dependencies
if: ${{ env.run-lint == 'true' || env.run-tests == 'true' }}
run: yarn install

- name: Lint
if: ${{ env.run-lint == 'true' }}
run: yarn lint

- name: Format
if: ${{ env.run-lint == 'true' }}
run: yarn format

- name: Test
if: ${{ env.run-tests == 'true' }}
run: yarn test

- name: Build
if: ${{ env.run-lint == 'true' }}
run: yarn build
27 changes: 25 additions & 2 deletions app/test/entrypoints/web/rest/orders/orders.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
OrderStartUsecaseImpl
} from '@core/usecases/orders/impl';
import {
OrderCreationRequest,
OrderCreationRequest, OrderEndRequest,
OrderQueryQuantityStatusRequest,
OrderQueryRequest
OrderQueryRequest, OrderStartRequest
} from '@entrypoints/web/rest/orders/request';
import {
OrderCreateResponse,
Expand Down Expand Up @@ -141,4 +141,27 @@ describe('OrdersController', () => {
expect(result).toEqual(expect.anything());
});

it('should call OrderStartUsecase.execute with correct parameters', async () => {
const mockRequest = { headers: {'x-api-key': '8c2e7d525bd34adfb52bb1fb24357a2d'}, body: {} } as any;
const mockDto: OrderStartRequest = {
startDatetime: "2024-12-29T22:59:41.255Z",
recordedLatitude: 13.174342,
recordedLongitude: 101.215167
}
await controller.startOrder(mockRequest, '6773205c93b1daa335239f03', mockDto);
expect(mockOrderStartUsecase.execute).toHaveBeenCalledWith(expect.anything());
});

it('should call OrderEndUsecase.execute with correct parameters', async () => {
const mockRequest = { headers: {'x-api-key': '8c2e7d525bd34adfb52bb1fb24357a2d'}, body: {} } as any;
const mockDto: OrderEndRequest = {
endDatetime: "2024-12-29T23:59:41.255Z",
recordedLatitude: 13.174342,
recordedLongitude: 101.215167,
comment: 'Finished'
}
await controller.endOrder(mockRequest, '6773205c93b1daa335239f03', mockDto);
expect(mockOrderEndUsecase.execute).toHaveBeenCalledWith(expect.anything());
});

});
Loading