1
0
mirror of https://github.com/SomboChea/ui synced 2024-11-15 02:34:26 +07:00
verdaccio-ui/jest/unit/components/__mocks__/token.ts
Ayush Sharma a4cdd145d2 feat: update date fns to v2 (#232)
* chore: updates date-fns@2

* chore: updates date-fns@2  to new apis

* chore: updates date-fns@2, updates format
2019-10-30 07:02:07 +01:00

32 lines
869 B
TypeScript

/**
* Token Utility
*/
import { Base64 } from 'js-base64';
import addHours from 'date-fns/addHours';
export function generateTokenWithTimeRange(limit = 0) {
const payload = {
username: 'verdaccio',
exp: Number.parseInt(String(addHours(new Date(), limit).getTime() / 1000), 10),
};
return `xxxxxx.${Base64.encode(JSON.stringify(payload))}.xxxxxx`;
}
export function generateTokenWithExpirationAsString() {
const payload = { username: 'verdaccio', exp: 'I am not a number' };
return `xxxxxx.${Base64.encode(JSON.stringify(payload))}.xxxxxx`;
}
export function generateInvalidToken() {
const payload = `invalidtoken`;
return `xxxxxx.${Base64.encode(payload)}.xxxxxx`;
}
export function generateTokenWithOutExpiration() {
const payload = {
username: 'verdaccio',
};
return `xxxxxx.${Base64.encode(JSON.stringify(payload))}.xxxxxx`;
}