generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from amosproj/dev
Merge Dev into main
- Loading branch information
Showing
21 changed files
with
3,868 additions
and
734 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,8 @@ apps/*/.env | |
.angular | ||
|
||
.cache/* | ||
|
||
# Test results | ||
apps/analyzer/.coverage | ||
reports/* | ||
coverage/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,11 @@ DATABASE_PORT=5433 | |
DATABASE_USER="postgres" | ||
DATABASE_PASSWORD="postgres" | ||
DATABASE_DATABASE="postgres" | ||
ANALYZER_URL="http://localhost:8000" | ||
ANALYZER_URL="http://localhost:8000" | ||
#Mailing | ||
MAIL_HOST=smtp.example.com | ||
MAIL_PORT=465 | ||
MAIL_USER=[email protected] | ||
MAIL_PASSWORD=topsecret | ||
MAIL_FROM=[email protected] | ||
MAILING_LIST=[email protected],[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Body, Controller, Logger, Post } from '@nestjs/common'; | ||
import { ApiOperation } from '@nestjs/swagger'; | ||
import { AlertingService } from './alerting.service'; | ||
import { AlertingInformationDto } from './dto/alertingInformationDto'; | ||
|
||
@Controller('alerting') | ||
export class AlertingController { | ||
readonly logger = new Logger(AlertingController.name); | ||
|
||
constructor(private readonly alertingService: AlertingService) {} | ||
|
||
@Post() | ||
@ApiOperation({ summary: 'Send an alert mail with the given informations.' }) | ||
async sendAlertMail( | ||
@Body() alertingInformationDto: AlertingInformationDto | ||
): Promise<void> { | ||
await this.alertingService.triggerAlertMail( | ||
alertingInformationDto.reason, | ||
alertingInformationDto.description | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AlertingService } from './alerting.service'; | ||
import { MailModule } from '../utils/mail/mail.module'; | ||
import { AlertingController } from './alerting.controller'; | ||
|
||
@Module({ | ||
imports: [MailModule], | ||
providers: [AlertingService], | ||
controllers: [AlertingController], | ||
}) | ||
export class AlertingModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AlertingService } from './alerting.service'; | ||
import { MailService } from '../utils/mail/mail.service'; | ||
|
||
describe('AlertingService', () => { | ||
let service: AlertingService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
AlertingService, | ||
{ | ||
provide: MailService, | ||
useValue: { | ||
sendAlertMail: jest.fn(), | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get(AlertingService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { MailService } from '../utils/mail/mail.service'; | ||
|
||
@Injectable() | ||
export class AlertingService { | ||
constructor(private mailService: MailService) {} | ||
|
||
async triggerAlertMail(reason: string, description: string) { | ||
await this.mailService.sendAlertMail(reason, description); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
apps/backend/src/app/alerting/dto/alertingInformationDto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { IsString } from 'class-validator'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class AlertingInformationDto { | ||
@ApiProperty({ | ||
description: 'Reason for the alert', | ||
required: true, | ||
}) | ||
@IsString() | ||
reason!: string; | ||
|
||
@ApiProperty({ | ||
description: 'Description of the alert', | ||
required: true, | ||
}) | ||
@IsString() | ||
description!: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
apps/backend/src/app/backupData/backupData.controller.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { INestApplication } from '@nestjs/common'; | ||
import request from 'supertest'; | ||
import { getRepositoryToken } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { BackupDataEntity } from './entity/backupData.entity'; | ||
import { CreateBackupDataDto } from './dto/createBackupData.dto'; | ||
import { BackupDataModule } from './backupData.module'; | ||
|
||
const mockBackupDataEntity: BackupDataEntity = { | ||
id: '123e4567-e89b-12d3-a456-426614174062', | ||
sizeMB: 100, | ||
creationDate: new Date('2023-12-30 00:00:00.000000'), | ||
bio: 'Test Bio', | ||
}; | ||
|
||
const mockBackupDataRepository = { | ||
save: jest | ||
.fn() | ||
.mockImplementation((backupData) => Promise.resolve(backupData)), | ||
findOne: jest | ||
.fn() | ||
.mockImplementation(({ where: { id } }) => | ||
Promise.resolve({ ...mockBackupDataEntity, id }) | ||
), | ||
|
||
findAndCount: jest | ||
.fn() | ||
.mockImplementation(() => Promise.resolve([[mockBackupDataEntity], 1])), | ||
}; | ||
|
||
describe('BackupDataController (e2e)', () => { | ||
let app: INestApplication; | ||
let repository: Repository<BackupDataEntity>; | ||
|
||
beforeAll(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
imports: [BackupDataModule], | ||
}) | ||
.overrideProvider(getRepositoryToken(BackupDataEntity)) | ||
.useValue(mockBackupDataRepository) | ||
.compile(); | ||
|
||
repository = module.get(getRepositoryToken(BackupDataEntity)); | ||
|
||
app = module.createNestApplication(); | ||
await app.init(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
|
||
it('/backupData (POST) should create new backup data entry', async () => { | ||
const createBackupDataDto: CreateBackupDataDto = { | ||
id: '1', | ||
sizeMB: 100, | ||
creationDate: new Date(), | ||
bio: 'Test Bio 1', | ||
}; | ||
|
||
const response = await request(app.getHttpServer()) | ||
.post('/backupData') | ||
.send(createBackupDataDto) | ||
.expect(201); | ||
|
||
expect(response.body).toEqual({ | ||
id: createBackupDataDto.id, | ||
sizeMB: createBackupDataDto.sizeMB, | ||
creationDate: createBackupDataDto.creationDate.toISOString(), | ||
bio: createBackupDataDto.bio, | ||
}); | ||
|
||
expect(mockBackupDataRepository.save).toBeCalledWith({ | ||
...createBackupDataDto, | ||
creationDate: createBackupDataDto.creationDate.toISOString(), | ||
}); | ||
}); | ||
it('/backupData/:id (GET) should return a backup data entry by id', async () => { | ||
const response = await request(app.getHttpServer()) | ||
.get(`/backupData/${mockBackupDataEntity.id}`) | ||
.expect(200); | ||
|
||
expect(response.body).toEqual({ | ||
...mockBackupDataEntity, | ||
creationDate: mockBackupDataEntity.creationDate.toISOString(), | ||
}); | ||
|
||
expect(mockBackupDataRepository.findOne).toBeCalledWith({ | ||
where: { id: mockBackupDataEntity.id }, | ||
}); | ||
}); | ||
|
||
it('/backupData (GET) with pagination should return paginated backup data entries', async () => { | ||
const response = await request(app.getHttpServer()) | ||
.get('/backupData?offset=0&limit=1') | ||
.expect(200); | ||
|
||
expect(response.body).toEqual({ | ||
data: [ | ||
{ | ||
...mockBackupDataEntity, | ||
creationDate: mockBackupDataEntity.creationDate.toISOString(), | ||
}, | ||
], | ||
paginationData: { | ||
limit: '1', | ||
offset: '0', | ||
total: 1, | ||
}, | ||
}); | ||
|
||
expect(mockBackupDataRepository.findAndCount).toBeCalledWith({ | ||
skip: '0', | ||
take: '1', | ||
order: { creationDate: 'DESC' }, | ||
where: {}, | ||
}); | ||
}); | ||
|
||
it('/backupData (GET) with filters should return filtered backup data entries', async () => { | ||
const response = await request(app.getHttpServer()) | ||
.get('/backupData?bio=Test') | ||
.expect(200); | ||
|
||
expect(response.body).toEqual({ | ||
data: [ | ||
{ | ||
...mockBackupDataEntity, | ||
creationDate: mockBackupDataEntity.creationDate.toISOString(), | ||
}, | ||
], | ||
paginationData: { | ||
total: 1, | ||
}, | ||
}); | ||
|
||
expect(mockBackupDataRepository.findAndCount).toBeCalledWith({ | ||
order: { creationDate: 'DESC' }, | ||
where: { bio: expect.any(Object) }, | ||
}); | ||
}); | ||
|
||
it('/backupData (GET) with date range should return backup data entries within date range', async () => { | ||
const response = await request(app.getHttpServer()) | ||
.get('/backupData?fromDate=2023-12-01&toDate=2023-12-31') | ||
.expect(200); | ||
|
||
expect(response.body).toEqual({ | ||
data: [ | ||
{ | ||
...mockBackupDataEntity, | ||
creationDate: mockBackupDataEntity.creationDate.toISOString(), | ||
}, | ||
], | ||
paginationData: { | ||
total: 1, | ||
}, | ||
}); | ||
|
||
expect(mockBackupDataRepository.findAndCount).toBeCalledWith({ | ||
order: { creationDate: 'DESC' }, | ||
where: { creationDate: expect.any(Object) }, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.