forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.service.spec.ts
More file actions
74 lines (67 loc) · 2 KB
/
Copy pathauth.service.spec.ts
File metadata and controls
74 lines (67 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Test, TestingModule } from '@nestjs/testing';
import { AuthService } from './auth.service';
import { JwtService } from '@nestjs/jwt';
import { PrismaService } from '../../infra/prisma/prisma.service';
describe('AuthService', () => {
let service: AuthService;
let jwtService: JwtService;
let prismaService: PrismaService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
AuthService,
{
provide: JwtService,
useValue: {
sign: jest.fn().mockReturnValue('test-token'),
},
},
{
provide: PrismaService,
useValue: {
user: {
upsert: jest.fn().mockResolvedValue({
id: 'user-id',
walletAddress: 'wallet-address',
}),
},
},
},
],
}).compile();
service = module.get<AuthService>(AuthService);
jwtService = module.get<JwtService>(JwtService);
prismaService = module.get<PrismaService>(PrismaService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
describe('connectWallet', () => {
it('should connect wallet and return token and user', async () => {
const connectWalletDto = {
walletAddress: 'wallet-address',
signature: 'signature',
message: 'message',
};
const result = await service.connectWallet(connectWalletDto);
expect(result).toEqual({
token: 'test-token',
user: {
id: 'user-id',
walletAddress: 'wallet-address',
},
});
expect(prismaService.user.upsert).toHaveBeenCalledWith({
where: { walletAddress: connectWalletDto.walletAddress },
update: {},
create: {
walletAddress: connectWalletDto.walletAddress,
},
});
expect(jwtService.sign).toHaveBeenCalledWith({
sub: 'user-id',
walletAddress: 'wallet-address',
});
});
});
});