mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
parent
c8a007684a
commit
2a54ace005
@ -8,6 +8,7 @@ const TABLE = 'personal_access_tokens';
|
||||
|
||||
const PAT_COLUMNS = [
|
||||
'secret',
|
||||
'description',
|
||||
'user_id',
|
||||
'expires_at',
|
||||
'created_at',
|
||||
@ -21,16 +22,18 @@ const fromRow = (row) => {
|
||||
return new Pat({
|
||||
secret: row.secret,
|
||||
userId: row.user_id,
|
||||
description: row.description,
|
||||
createdAt: row.created_at,
|
||||
seenAt: row.seen_at,
|
||||
expiresAt: row.expires_at,
|
||||
});
|
||||
};
|
||||
|
||||
const toRow = (user: IPat) => ({
|
||||
secret: user.secret,
|
||||
user_id: user.userId,
|
||||
expires_at: user.expiresAt,
|
||||
const toRow = (pat: IPat) => ({
|
||||
secret: pat.secret,
|
||||
description: pat.description,
|
||||
user_id: pat.userId,
|
||||
expires_at: pat.expiresAt,
|
||||
});
|
||||
|
||||
export default class PatStore implements IPatStore {
|
||||
|
@ -1,5 +1,6 @@
|
||||
export interface IPat {
|
||||
secret: string;
|
||||
description: string;
|
||||
userId: number;
|
||||
expiresAt?: Date;
|
||||
createdAt?: Date;
|
||||
@ -9,6 +10,8 @@ export interface IPat {
|
||||
export default class Pat implements IPat {
|
||||
secret: string;
|
||||
|
||||
description: string;
|
||||
|
||||
userId: number;
|
||||
|
||||
expiresAt: Date;
|
||||
@ -17,11 +20,19 @@ export default class Pat implements IPat {
|
||||
|
||||
createdAt: Date;
|
||||
|
||||
constructor({ secret, userId, expiresAt, seenAt, createdAt }: IPat) {
|
||||
constructor({
|
||||
secret,
|
||||
userId,
|
||||
expiresAt,
|
||||
seenAt,
|
||||
createdAt,
|
||||
description,
|
||||
}: IPat) {
|
||||
this.secret = secret;
|
||||
this.userId = userId;
|
||||
this.expiresAt = expiresAt;
|
||||
this.seenAt = seenAt;
|
||||
this.createdAt = createdAt;
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ exports.up = function (db, cb) {
|
||||
`
|
||||
CREATE TABLE personal_access_tokens (
|
||||
secret text not null primary key,
|
||||
description text,
|
||||
user_id integer not null references users (id) ON DELETE CASCADE,
|
||||
expires_at timestamp with time zone NOT NULL,
|
||||
seen_at timestamp with time zone,
|
||||
|
@ -26,17 +26,20 @@ afterAll(async () => {
|
||||
});
|
||||
|
||||
test('should create a PAT', async () => {
|
||||
const description = 'expected description';
|
||||
const { request } = app;
|
||||
|
||||
const { body } = await request
|
||||
.post('/api/admin/user/tokens')
|
||||
.send({
|
||||
expiresAt: tomorrow,
|
||||
description: description,
|
||||
} as IPat)
|
||||
.set('Content-Type', 'application/json')
|
||||
.expect(201);
|
||||
|
||||
expect(new Date(body.expiresAt)).toEqual(tomorrow);
|
||||
expect(body.description).toEqual(description);
|
||||
});
|
||||
|
||||
test('should delete the PAT', async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user