test: add access token factory
This commit is contained in:
13
packages/backend/test/factories/access-token.js
Normal file
13
packages/backend/test/factories/access-token.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import crypto from 'crypto';
|
||||
import AccessToken from '../../src/models/access-token.js';
|
||||
import { createUser } from './user.js';
|
||||
|
||||
export const createAccessToken = async (params = {}) => {
|
||||
params.userId = params.userId || (await createUser()).id;
|
||||
params.token = params.token || (await crypto.randomBytes(48).toString('hex'));
|
||||
params.expiresIn = params.expiresIn || 14 * 24 * 60 * 60; // 14 days in seconds
|
||||
|
||||
const accessToken = await AccessToken.query().insertAndFetch(params);
|
||||
|
||||
return accessToken;
|
||||
};
|
Reference in New Issue
Block a user