77 createApiKey ,
88 deleteApiKey ,
99 getApiKeysForProject ,
10- projectHasKey
10+ projectHasKey ,
11+ setApiKeyName
1112} from './api-key.repository'
1213
1314beforeEach ( async ( ) => {
@@ -40,6 +41,14 @@ describe('ApiKey Repository', () => {
4041 expect ( result ) . includes ( key2 . key )
4142 } )
4243
44+ it ( 'should retrieve the name of the apiKey when it is created with one' , async ( ) => {
45+ const name = 'some key name'
46+ const key = await createApiKey ( projectId , name )
47+ const result = await getApiKeysForProject ( projectId )
48+
49+ expect ( result . find ( ( it ) => it . key === key . key ) ?. name ) . toBe ( name )
50+ } )
51+
4352 it ( 'should no longer find deleted keys' , async ( ) => {
4453 const key = await createApiKey ( projectId )
4554
@@ -62,6 +71,41 @@ describe('ApiKey Repository', () => {
6271 } )
6372 } )
6473
74+ describe ( 'setApiKeyName' , ( ) => {
75+ it ( 'should be able to set a name when previously there was none' , async ( ) => {
76+ const key = await createApiKey ( projectId )
77+ const initialRetrieval = await getApiKeysForProject ( projectId ) . then ( ( it ) =>
78+ it . find ( ( apiKey ) => apiKey . key === key . key )
79+ )
80+
81+ expect ( initialRetrieval ?. name ) . toBeFalsy ( )
82+ const updatedName = 'some new apiKeyName'
83+ await setApiKeyName ( key . id , updatedName )
84+
85+ const secondRetrieval = await getApiKeysForProject ( projectId ) . then ( ( it ) =>
86+ it . find ( ( apiKey ) => apiKey . key === key . key )
87+ )
88+ expect ( secondRetrieval ?. name ) . toBe ( updatedName )
89+ } )
90+
91+ it ( 'should be able to set the name' , async ( ) => {
92+ const initialName = 'my personal api key'
93+ const key = await createApiKey ( projectId , initialName )
94+ const initialRetrieval = await getApiKeysForProject ( projectId ) . then ( ( it ) =>
95+ it . find ( ( apiKey ) => apiKey . key === key . key )
96+ )
97+
98+ expect ( initialRetrieval ?. name ) . toBe ( initialName )
99+ const updatedName = 'some new apiKeyName'
100+ await setApiKeyName ( key . id , updatedName )
101+
102+ const secondRetrieval = await getApiKeysForProject ( projectId ) . then ( ( it ) =>
103+ it . find ( ( apiKey ) => apiKey . key === key . key )
104+ )
105+ expect ( secondRetrieval ?. name ) . toBe ( updatedName )
106+ } )
107+ } )
108+
65109 describe ( 'projectHasKey' , ( ) => {
66110 it ( 'should return true if there is a key for the project' , async ( ) => {
67111 const key = await createApiKey ( projectId )
0 commit comments