-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Audit log and unit tests updated
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# compiled output | ||
#/dist | ||
/node_modules | ||
|
||
.env | ||
# Logs | ||
logs | ||
*.log | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export declare class AppModule { | ||
import { MiddlewareConsumer, NestModule } from '@nestjs/common'; | ||
export declare class AppModule implements NestModule { | ||
configure(consumer: MiddlewareConsumer): void; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/// <reference types="mongoose/types/pipelinestage" /> | ||
/// <reference types="mongoose/types/error" /> | ||
/// <reference types="mongoose/types/connection" /> | ||
import { Document } from 'mongoose'; | ||
export declare type AuditDocument = Audit & Document; | ||
export declare class Audit { | ||
createdAt: Date; | ||
method: string; | ||
originalUrl: string; | ||
statusCode: number; | ||
contentLength: string; | ||
userAgent: string; | ||
ip: string; | ||
params: string; | ||
body: string; | ||
user: string; | ||
} | ||
export declare const AuditSchema: import("mongoose").Schema<Document<Audit, any, any>, import("mongoose").Model<Document<Audit, any, any>, any, any, any>, any, any>; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NestMiddleware } from '@nestjs/common'; | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { AuditDocument } from 'src/schemas/audit.schema'; | ||
import { Model } from 'mongoose'; | ||
import { JwtService } from '@nestjs/jwt'; | ||
export declare class AuditLogger implements NestMiddleware { | ||
private auditModel; | ||
private jwt; | ||
constructor(auditModel: Model<AuditDocument>, jwt: JwtService); | ||
private logger; | ||
use(request: Request, response: Response, next: NextFunction): void; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AuthController } from './auth.controller'; | ||
import {AuthService} from "./auth.service"; | ||
|
||
describe('AuthController', () => { | ||
let controller: AuthController; | ||
const mockAuthService = {}; | ||
const mockAuthService = { | ||
signin:jest.fn(()=>({ | ||
access_token:"lskjdf", | ||
refresh_token:"klsdjf" | ||
})) | ||
}; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
|
@@ -17,4 +23,9 @@ describe('AuthController', () => { | |
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
|
||
it("should do something", async ()=>{ | ||
expect(await controller.signin({email:"[email protected]", password:"some pwd"})).toStrictEqual({ access_token:"lskjdf", | ||
refresh_token:"klsdjf"}) | ||
}) | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | ||
import { Document } from 'mongoose'; | ||
|
||
export type AuditDocument = Audit & Document; | ||
@Schema() | ||
export class Audit { | ||
@Prop({ default: new Date() }) | ||
createdAt: Date; | ||
|
||
@Prop() | ||
method: string; | ||
|
||
@Prop() | ||
originalUrl: string; | ||
|
||
@Prop() | ||
statusCode: number; | ||
|
||
@Prop() | ||
contentLength: string; | ||
|
||
@Prop() | ||
userAgent:string; | ||
|
||
@Prop() | ||
ip:string | ||
|
||
@Prop() | ||
params:string | ||
|
||
@Prop() | ||
body:string | ||
|
||
@Prop() | ||
user:string | ||
} | ||
|
||
export const AuditSchema = SchemaFactory.createForClass(Audit); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { UserController } from './user.controller'; | ||
import { UserService } from './user.service'; | ||
|
||
describe('UserController', () => { | ||
let controller: UserController; | ||
const mock = { | ||
getAllUsers:jest.fn(async ()=>([ | ||
{} | ||
])) | ||
])), | ||
|
||
updateUser:jest.fn(async()=>({})), | ||
deleteUser:jest.fn(async()=>({})) | ||
} | ||
|
||
beforeEach(async () => { | ||
|
@@ -25,4 +29,40 @@ const mock = { | |
it("should return all users", async ()=>{ | ||
expect(await controller.getAllUsers()).toEqual([{}]) | ||
}) | ||
const date = new Date() | ||
it("should return a specific user", async()=>{ | ||
expect(controller.whoAmI({ | ||
email:"[email protected]", | ||
name:"Jaroslav", | ||
surname:"Huss", | ||
createdAt:date, | ||
updatedAt:date, | ||
authLevel:"iot-admin", | ||
isUserApproved:true, | ||
password:"somefailstring", | ||
lastLoggedIn:date, | ||
refresh_token:"fake_token" | ||
})).toStrictEqual({ email:"[email protected]", | ||
name:"Jaroslav", | ||
surname:"Huss", | ||
createdAt:date, | ||
updatedAt:date, | ||
authLevel:"iot-admin", | ||
isUserApproved:true, | ||
lastLoggedIn:date, | ||
refresh_token:"fake_token"}) | ||
}) | ||
|
||
it("should delete a user", async ()=>{ | ||
expect(await controller.deleteUser("fakeid")).toStrictEqual({}) | ||
}) | ||
|
||
it("should", async ()=>{ | ||
expect(await controller.updateUser({ email:"[email protected]", | ||
name:"Jaroslav", | ||
surname:"Huss", | ||
authLevel:"iot-admin", | ||
isUserApproved:true, | ||
}, "fakeid")).toStrictEqual({}) | ||
}) | ||
}); |