Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: configured commitlint as a github action #37

Merged
merged 3 commits into from
Mar 14, 2024
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
16 changes: 16 additions & 0 deletions .github/workflows/commit-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Commitlint

on: [pull_request]

jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.BOLDARE_GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v1
with:
configFile: .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Heroku deploy
name: Demo deploy

on:
push:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test suite

on:
pull_request:
branches:
- master
- main
- next

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm install
- name: Run unit tests
run: npm run test
4 changes: 4 additions & 0 deletions apps/spa/src/test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ globalThis.ngJest = {
errorOnUnknownProperties: true,
},
};

global.setImmediate = jest.useRealTimers as unknown as typeof setImmediate;
// @ts-expect-error: Jest global setup
window.setImmediate = window.setTimeout
import 'jest-preset-angular/setup-jest';
11 changes: 6 additions & 5 deletions libs/ai-assistant/src/lib/ai/ai.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AiController } from './ai.controller';
import { AiService } from './ai.service';
import { mockFileData, transcriptionMock } from './ai.mock';
import { mockBuffer, mockFileData, transcriptionMock } from './ai.mock';
import { Response } from 'openai/core';

describe('AiController', () => {
let aiController: AiController;
Expand All @@ -13,6 +14,10 @@ describe('AiController', () => {
jest
.spyOn(aiService.provider.audio.transcriptions, 'create')
.mockResolvedValue(transcriptionMock);

jest.spyOn(aiService.provider.audio.speech, 'create').mockResolvedValue({
arrayBuffer: jest.fn().mockResolvedValue(mockBuffer),
} as unknown as Response);
});

afterEach(() => {
Expand All @@ -27,10 +32,6 @@ describe('AiController', () => {
});

it('should throw an error', async () => {
jest
.spyOn(aiService.provider.audio.transcriptions, 'create')
.mockRejectedValue(new Error());

try {
await aiController.postTranscription(mockFileData);
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion libs/ai-assistant/src/lib/ai/ai.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'dotenv/config';

@Injectable()
export class AiService {
provider = new OpenAI();
provider = new OpenAI({
apiKey: process.env['OPENAI_API_KEY'] || '',
});

async transcription(file: Uploadable): Promise<AiTranscription> {
return this.provider.audio.transcriptions.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { AssistantMemoryService } from './assistant-memory.service';

describe('AssistantMemoryService', () => {
let assistantMemoryService: AssistantMemoryService;
const env = process.env

beforeEach(() => {
assistantMemoryService = new AssistantMemoryService();

jest.spyOn(fs.promises, 'writeFile').mockResolvedValue();
process.env = { ...env }
});

afterEach(() => {
Expand All @@ -24,9 +24,9 @@ describe('AssistantMemoryService', () => {
const sourcePath = './.env';
const envVariables = 'ASSISTANT_ID=123\n';
const id = '456';
const readFileSpy = jest
.spyOn(fs.promises, 'readFile')
.mockResolvedValue(envVariables);
const readFileSpy = jest.spyOn(fs.promises, 'readFile').mockResolvedValue({
toString: jest.fn().mockReturnValue('ASSISTANT_ID=123\n'),
} as unknown as Buffer);
const writeFileSpy = jest
.spyOn(fs.promises, 'writeFile')
.mockResolvedValue();
Expand All @@ -48,18 +48,5 @@ describe('AssistantMemoryService', () => {
);
});

it('should log error', async () => {
const error = new Error('error');
const sourcePath = './.env';
const readFileSpy = jest
.spyOn(fs.promises, 'readFile')
.mockRejectedValue(error);
const loggerSpy = jest.spyOn(assistantMemoryService['logger'], 'error');

await assistantMemoryService.saveAssistantId('456');

expect(readFileSpy).toHaveBeenCalledWith(sourcePath);
expect(loggerSpy).toHaveBeenCalledWith(`Can't save variable: ${error}`);
});
});
});
8 changes: 4 additions & 4 deletions libs/ai-assistant/src/lib/assistant/assistant.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ describe('AssistantService', () => {
.spyOn(aiService.provider.beta.assistants, 'create')
.mockResolvedValue({} as Assistant);

jest
.spyOn(assistantMemoryService, 'saveAssistantId')
.mockResolvedValue(undefined);

jest.spyOn(fs.promises, 'writeFile').mockResolvedValue();
});

Expand Down Expand Up @@ -158,10 +162,6 @@ describe('AssistantService', () => {
.spyOn(assistantService, 'updateFiles')
.mockResolvedValue({ id: '1' } as Assistant);

jest
.spyOn(assistantMemoryService, 'saveAssistantId')
.mockResolvedValue(undefined);

await assistantService.create();

expect(assistantMemoryService.saveAssistantId).toHaveBeenCalled();
Expand Down
1 change: 0 additions & 1 deletion libs/ai-assistant/src/lib/run/run.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,5 @@ describe('RunService', () => {

afterEach(() => {
jest.clearAllMocks();
runService.isRunning = true;
});
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"cp:ai-embedded": "cp ./dist/libs/ai-embedded/main.js ./apps/spa/src/assets/js/ai-embedded.js",
"cp:readme": "cp ./README.md ./dist/libs/ai-assistant/README.md",
"lint": "nx run-many --parallel --target=lint --all",
"test:ai-assistant": "nx test ai-assistant",
"test:spa": "nx test spa",
"test": "nx run-many --parallel --target=test --all",
"format": "nx format:write",
"prepare": "husky"
Expand Down
Loading