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