-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsetOtp.test.ts
63 lines (51 loc) · 1.67 KB
/
setOtp.test.ts
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
import { NotificationChannelType } from '@dm3-org/dm3-lib-delivery';
import { IDatabase, Redis, getDatabase, getRedisClient } from '../getDatabase';
import winston from 'winston';
const USER_ADDRESS = '0x25A643B6e52864d0eD816F1E43c0CF49C83B8292';
global.logger = winston.createLogger({
transports: [new winston.transports.Console()],
});
describe('Email Verification OTP', () => {
let redisClient: Redis;
let db: IDatabase;
beforeEach(async () => {
redisClient = await getRedisClient();
db = await getDatabase(redisClient);
await redisClient.flushDb();
});
afterEach(async () => {
await redisClient.flushDb();
await redisClient.disconnect();
});
it('Set Email Verification OTP', async () => {
const otp = '19283';
const generatedAt = new Date();
// fetch OTP from Redis
const priorOtp = await db.getOtp(
USER_ADDRESS,
NotificationChannelType.EMAIL,
);
// User's email otp is null initially
expect(priorOtp).toEqual(null);
// set email OTP
await db.setOtp(
USER_ADDRESS,
otp,
NotificationChannelType.EMAIL,
generatedAt,
);
// fetch OTP from Redis after setting OTP
const afterSettingOtp = await db.getOtp(
USER_ADDRESS,
NotificationChannelType.EMAIL,
);
const expectedData = {
generatedAt: generatedAt,
otp: otp,
type: NotificationChannelType.EMAIL,
};
expect(JSON.stringify(afterSettingOtp)).toEqual(
JSON.stringify(expectedData),
);
});
});