forked from hypersign-protocol/entity-api-service
-
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
Showing
5 changed files
with
145 additions
and
74 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 |
---|---|---|
@@ -1,18 +1,63 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AppAuthController } from './app-auth.controller'; | ||
import { AppAuthService } from '../services/app-auth.service'; | ||
|
||
describe('AppAuthController', () => { | ||
let controller: AppAuthController; | ||
const mockApp = { | ||
appName: 'new fyre app', | ||
appId: '3977ed2d3c26824d77c08c24aa7f22dbee81', | ||
edvId: 'hs:studio-api:app:3977ed2d3c26824d77c08c24aa7f22dbee81', | ||
walletAddress: 'hid1yam5kyrcyvrpah750zfhsjuqg5u2lfc3th2wul', | ||
whitelistedCors: ['*', 'http://locahost:8080'], | ||
logoUrl: '', | ||
subdomain: 'ent_5f9e3e0', | ||
tenantUrl: 'http://ent_5f9e3e0.localhost:8080', | ||
}; | ||
const findAppResp = [ | ||
{ | ||
totalCount: 1, | ||
data: [mockApp], | ||
}, | ||
]; | ||
|
||
const createAppResp = { | ||
appName: 'new fyre app', | ||
appId: '3977ed2d3c26824d77c08c24aa7f22dbee81', | ||
edvId: 'hs:studio-api:app:3977ed2d3c26824d77c08c24aa7f22dbee81', | ||
kmsId: 'hs:doc:vnc7vkyvhfmcr3hsp450cxtyunlcnappu4m2ef3kmgi', | ||
walletAddress: 'hid1yam5kyrcyvrpah750zfhsjuqg5u2lfc3th2wul', | ||
whitelistedCors: ['*', 'http://locahost:8080'], | ||
logoUrl: '', | ||
subdomain: 'ent_5f9e3e0', | ||
apiSecretKey: | ||
'db1ee5a1282b2f03da1c1b6c2dc6e.66bff8a7785a6e171cde95c4f9f9f7e926ca76b3688d9622e320062c4749aca1d569de5fffc5bfd6773e57542b4677d4d', | ||
tenantUrl: 'http://ent_5f9e3e0.localhost:8080/', | ||
}; | ||
|
||
describe('AppAuthController', () => { | ||
let appAuthcontroller: AppAuthController; | ||
let spyAppAuthService: AppAuthService; | ||
beforeEach(async () => { | ||
const AppAuthProvider = { | ||
provide: AppAuthService, | ||
useFactory: () => ({ | ||
getAllApps: jest.fn().mockResolvedValue(findAppResp), | ||
getAppById: jest.fn().mockResolvedValue(mockApp), | ||
createAnApp: jest.fn().mockResolvedValue(createAppResp), | ||
updateAnApp: jest.fn().mockResolvedValue(mockApp), | ||
deleteApp: jest.fn().mockResolvedValue(mockApp), | ||
reGenerateAppSecretKey: jest.fn().mockResolvedValue(mockApp), | ||
}), | ||
}; | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [AppAuthController], | ||
providers: [AppAuthService], | ||
}).compile(); | ||
|
||
controller = module.get<AppAuthController>(AppAuthController); | ||
appAuthcontroller = module.get<AppAuthController>(AppAuthController); | ||
spyAppAuthService = module.get<AppAuthService>(AppAuthService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
expect(appAuthcontroller).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
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 |
---|---|---|
@@ -1,18 +1,99 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { UserController } from './user.controller'; | ||
|
||
import { UserService } from '../services/user.service'; | ||
import { UserRepository } from '../repository/user.repository'; | ||
const mockUser = { | ||
_id: '641d2e711f35ed7575931', | ||
email: 'varshakumari370@gmail.com', | ||
userId: 'ab8d48e0-60eb-437c-9a86-e063080b2943', | ||
did: 'did:hid:testnet:z2JFAEgfG5b7PhjHmCGuAeRPzqUaJ3Te9LUycbDMRzDwH', | ||
createdAt: '2023-11-13T15:24:49.053Z', | ||
updatedAt: '2023-11-13T15:24:49.053Z', | ||
}; | ||
const reqBody = { | ||
hypersign: { | ||
data: { | ||
user: { | ||
email: 'varshakumari370@gmail.com', | ||
appUserID: 'ab8d48e0-60eb-437c-9a86-e063080b2943', | ||
did: 'did:hid:testnet:z2JFAEgfG5b7PhjHmCGuAeRPzqUaJ3Te9LUycbDMRzDwH', | ||
}, | ||
}, | ||
}, | ||
}; | ||
const authenticateResp = { | ||
error: null, | ||
message: { | ||
email: 'varshakumari370@gmail.com', | ||
appUserID: 'ab8d48e0-60eb-437c-9a86-e063080b2943', | ||
did: 'did:hid:testnet:z2JFAEgfG5b7PhjHmCGuAeRPzqUaJ3Te9LUycbDMRzDwH', | ||
}, | ||
status: 200, | ||
}; | ||
const authorizeResp = { | ||
...authenticateResp, | ||
message: { | ||
user: { | ||
email: 'varshakumari370@gmail.com', | ||
appUserID: 'ab8d48e0-60eb-437c-9a86-e063080b2943', | ||
did: 'did:hid:testnet:z2JFAEgfG5b7PhjHmCGuAeRPzqUaJ3Te9LUycbDMRzDwH', | ||
}, | ||
}, | ||
}; | ||
describe('UserController', () => { | ||
let controller: UserController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [UserController], | ||
}).compile(); | ||
|
||
controller = module.get<UserController>(UserController); | ||
let userController: UserController; | ||
let spyUserService: UserService; | ||
describe('authenticate() method', () => { | ||
it('should be register new user', async () => { | ||
const mockFindOneUser = jest.fn().mockResolvedValue({}); | ||
const createAUser = jest.fn().mockResolvedValue(mockUser); | ||
const userRepository = { | ||
findOne: mockFindOneUser, | ||
create: createAUser, | ||
}; | ||
const userModule: TestingModule = await Test.createTestingModule({ | ||
controllers: [UserController], | ||
providers: [ | ||
UserRepository, | ||
{ provide: UserRepository, useValue: userRepository }, | ||
], | ||
}).compile(); | ||
userController = userModule.get<UserController>(UserController); | ||
const req = {}; | ||
const res = { | ||
status: jest.fn(() => res), | ||
json: jest.fn(), | ||
}; | ||
await userController.authenticate(res, req, reqBody); | ||
expect(res.status).toHaveBeenCalledWith(200); | ||
expect(res.json).toHaveBeenCalledWith(authenticateResp); | ||
}); | ||
}); | ||
describe('authorize() method', () => { | ||
it('should be able to authorize a user and get user inforamtion as response', async () => { | ||
const mockFindOneUser = jest.fn().mockResolvedValue({}); | ||
const createAUser = jest.fn().mockResolvedValue(mockUser); | ||
const userRepository = { | ||
findOne: mockFindOneUser, | ||
create: createAUser, | ||
}; | ||
const userModule: TestingModule = await Test.createTestingModule({ | ||
controllers: [UserController], | ||
providers: [ | ||
UserRepository, | ||
{ provide: UserRepository, useValue: userRepository }, | ||
], | ||
}).compile(); | ||
userController = userModule.get<UserController>(UserController); | ||
const req = {}; | ||
const res = { | ||
status: jest.fn(() => res), | ||
json: jest.fn(), | ||
}; | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
await userController.authorize(res, req, reqBody); | ||
expect(res.status).toHaveBeenCalledWith(200); | ||
expect(res.json).toHaveBeenCalledWith(authorizeResp); | ||
}); | ||
}); | ||
}); |
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