-
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.
- Loading branch information
1 parent
cf5437b
commit 4f86a38
Showing
16 changed files
with
244 additions
and
41 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
MONGODB_URI=mongodb://127.0.0.1:27017/AIBackend | ||
JWT_SECRET_KEY=123 | ||
|
||
MAIL_HOST=email-smtp.eu-north-1.amazonaws.com | ||
MAIL_PORT=25 | ||
MAIL_SECURE=false | ||
MAIL_USERNAME=AKIA5FTY7FF2ADQZF66C | ||
MAIL_PASSWORD=BBoXNWCEzb7GgfK5La+alTH+pAqbIlyegV0sT4Bz8k9V | ||
MAIL_DEFAULT_FROM=[email protected] | ||
|
||
NOTIFICATION_CHANNEL=mail | ||
|
||
REDIS_HOST=127.0.0.1 | ||
REDIS_PORT=6379 | ||
|
||
OPENAI_API_KEY= | ||
ORGANIZATON_ID= | ||
|
||
SITE_URL=http://localhost:5173/ |
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
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
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
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,6 @@ | ||
import { registerAs } from '@nestjs/config'; | ||
|
||
export default registerAs('roles', () => ({ | ||
ADMIN_ROLE: 'admin', | ||
USER_ROLE: 'user', | ||
})); |
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 |
---|---|---|
@@ -1,20 +1,52 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { DailyController } from './daily.controller'; | ||
import { DailyService } from './daily.service'; | ||
import { REQUEST } from '@nestjs/core'; | ||
import { CreateDailyDto } from './dto/create-daily.dto'; | ||
import { AuthGuard } from '../auth/guards/auth.guard'; | ||
import { CanActivate } from '@nestjs/common'; | ||
|
||
describe('DailyController', () => { | ||
let controller: DailyController; | ||
let service: DailyService; | ||
|
||
const mockDailyService = { | ||
create: jest.fn((dto) => dto), | ||
}; | ||
|
||
const mock_ForceFailGuard: CanActivate = { canActivate: jest.fn(() => true) }; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [DailyController], | ||
providers: [DailyService], | ||
}).compile(); | ||
}) | ||
.overrideProvider(DailyService) | ||
.useValue(mockDailyService) | ||
.overrideGuard(AuthGuard) | ||
.useValue(mock_ForceFailGuard) | ||
.compile(); | ||
|
||
controller = module.get<DailyController>(DailyController); | ||
service = module.get<DailyService>(DailyService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
|
||
it('should call dailyService.create with correct parameters', async () => { | ||
const req = { user: { id: 1, name: 'Test User' } }; | ||
const createDailyDto: CreateDailyDto = { | ||
content: 'this is a test !', | ||
orderId: 1, | ||
}; | ||
|
||
const result = {}; | ||
|
||
jest.spyOn(service, 'create').mockResolvedValue(result); | ||
|
||
expect(await controller.create(req, createDailyDto)).toBe(result); | ||
expect(service.create).toHaveBeenCalledWith(createDailyDto, req.user); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,18 +1,72 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { DailyService } from './daily.service'; | ||
import { Daily } from './entities/daily.entity'; | ||
import { Model, ObjectId, Types } from 'mongoose'; | ||
import { getModelToken } from '@nestjs/mongoose'; | ||
import { CreateDailyDto } from './dto/create-daily.dto'; | ||
|
||
describe('DailyService', () => { | ||
let service: DailyService; | ||
let model: Model<Daily>; | ||
|
||
const mockUser = { | ||
sub: new Types.ObjectId('66479e05a279293d64585979'), | ||
name: 'Alp Emre Elmas', | ||
email: '[email protected]', | ||
}; | ||
|
||
const mockDaily = { | ||
user: new Types.ObjectId('66479e28a279293d64585982'), | ||
content: 'Test #1', | ||
orderId: 0, | ||
createdAt: '2024-05-17T17:53:54.050Z', | ||
updatedAt: '2024-05-17T17:53:54.050Z', | ||
_id: new Types.ObjectId('66479e28a279293d64585982'), | ||
__v: 0, | ||
}; | ||
|
||
const mockDailyService = { | ||
create: jest.fn(), | ||
/*findAll: jest.fn(), | ||
findOne: jest.fn(), | ||
order: jest.fn(), | ||
update: jest.fn(), | ||
remove: jest.fn(),*/ | ||
}; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [DailyService], | ||
providers: [ | ||
DailyService, | ||
{ | ||
provide: getModelToken(Daily.name), | ||
useValue: mockDailyService, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get<DailyService>(DailyService); | ||
model = module.get<Model<Daily>>(getModelToken(Daily.name)); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
|
||
it('should create a daily', async () => { | ||
const newDaily = { | ||
content: 'This is a test content.', | ||
orderId: 2, | ||
}; | ||
|
||
jest.fn().mockResolvedValue((mockDaily) => Promise.resolve(mockDaily)); | ||
|
||
const result = await service.create(newDaily as CreateDailyDto, mockUser); | ||
expect(result).toEqual({ | ||
_id: expect.any(Number), | ||
content: 'This is a test content.', | ||
}); | ||
|
||
expect(model.create).toHaveBeenCalledWith(newDaily); | ||
}); | ||
}); |
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
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,34 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { Model } from 'mongoose'; | ||
import { User } from '../entities/user.schema'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { Seeder } from 'nestjs-seeder'; | ||
import * as bcrypt from 'bcrypt'; | ||
import * as moment from 'moment/moment'; | ||
import { UserAndRoles } from '../entities/userRoles'; | ||
import { AuthService } from '../../auth/services/auth.service'; | ||
import { JwtService } from '@nestjs/jwt'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { Roles } from '../entities/roles.schema'; | ||
|
||
@Injectable() | ||
export class RolesSeeder implements Seeder { | ||
constructor( | ||
@InjectModel(UserAndRoles.name) | ||
private readonly rolesAndUser: Model<UserAndRoles>, | ||
@InjectModel(Roles.name) private readonly roles: Model<Roles>, | ||
private configService: ConfigService, | ||
) {} | ||
|
||
async seed(): Promise<any> { | ||
const roles = this.configService.get<string>('roles'); | ||
for (const [key, value] of Object.entries(roles)) { | ||
await this.roles.create({ name: value }); | ||
} | ||
} | ||
|
||
async drop(): Promise<any> { | ||
return this.roles.deleteMany({}); | ||
} | ||
} |
Oops, something went wrong.