fix(coreflow): Fix Coreflow identity lookup and response shape; improve API client tests and bump dependencies
This commit is contained in:
		| @@ -14,8 +14,10 @@ tap.preTask('should start cloudly', async () => { | ||||
| }); | ||||
|  | ||||
| tap.preTask('should create a new machine user for testing', async () => { | ||||
|   console.log('🔵 PreTask: Creating first machine user...'); | ||||
|   const machineUser = new testCloudly.authManager.CUser(); | ||||
|   machineUser.id = await testCloudly.authManager.CUser.getNewId(); | ||||
|   console.log(`  - User ID: ${machineUser.id}`); | ||||
|   machineUser.data = { | ||||
|     type: 'machine', | ||||
|     username: 'test', | ||||
| @@ -27,48 +29,103 @@ tap.preTask('should create a new machine user for testing', async () => { | ||||
|     }], | ||||
|     role: 'admin', | ||||
|   }; | ||||
|   console.log(`  - Username: ${machineUser.data.username}`); | ||||
|   console.log(`  - Role: ${machineUser.data.role}`); | ||||
|   console.log(`  - Token: 'test'`); | ||||
|   console.log(`  - Token roles: ${machineUser.data.tokens[0].assignedRoles}`); | ||||
|   await machineUser.save(); | ||||
|   console.log('✅ PreTask: First machine user saved successfully'); | ||||
| }); | ||||
|  | ||||
| tap.test('should create a new cloudlyApiClient', async () => { | ||||
|   console.log('🔵 Test: Creating CloudlyApiClient...'); | ||||
|   testClient = new cloudlyApiClient.CloudlyApiClient({ | ||||
|     registerAs: 'api', | ||||
|     cloudlyUrl: `http://${helpers.testCloudlyConfig.publicUrl}:${helpers.testCloudlyConfig.publicPort}`, | ||||
|   }); | ||||
|   console.log(`  - URL: http://${helpers.testCloudlyConfig.publicUrl}:${helpers.testCloudlyConfig.publicPort}`); | ||||
|   await testClient.start(); | ||||
|   console.log('✅ CloudlyApiClient started successfully'); | ||||
|   expect(testClient).toBeTruthy(); | ||||
| }); | ||||
|  | ||||
| tap.test('create a new machine user', async () => { | ||||
|   const machineUser = await testCloudly.authManager.CUser.createMachineUser('test', 'api'); | ||||
|   machineUser.data.tokens.push({ | ||||
|     token: 'test', | ||||
|     expiresAt: Date.now() + 3600 * 1000 * 24 * 365, | ||||
|     assignedRoles: ['api'], | ||||
|   }) | ||||
|   await machineUser.save(); | ||||
| }) | ||||
| tap.test('DEBUG: Check existing users', async () => { | ||||
|   console.log('🔍 DEBUG: Checking existing users in database...'); | ||||
|   const allUsers = await testCloudly.authManager.CUser.getInstances({}); | ||||
|   console.log(`  - Total users found: ${allUsers.length}`); | ||||
|   for (const user of allUsers) { | ||||
|     console.log(`  - User: ${user.data.username} (ID: ${user.id})`); | ||||
|     console.log(`    - Type: ${user.data.type}`); | ||||
|     console.log(`    - Role: ${user.data.role}`); | ||||
|     console.log(`    - Tokens: ${user.data.tokens.length}`); | ||||
|     for (const token of user.data.tokens) { | ||||
|       console.log(`      - Token: '${token.token}' | Roles: ${token.assignedRoles?.join(', ')}`); | ||||
|     } | ||||
|   } | ||||
| }); | ||||
|  | ||||
| tap.test('should get an identity', async () => { | ||||
|   const identity = await testClient.getIdentityByToken('test'); | ||||
|   expect(identity).toBeTruthy(); | ||||
|   console.log(identity); | ||||
|   console.log('🔵 Test: Getting identity by token...'); | ||||
|   console.log(`  - Using token: 'test'`); | ||||
|   console.log(`  - API URL: http://${helpers.testCloudlyConfig.publicUrl}:${helpers.testCloudlyConfig.publicPort}`); | ||||
|    | ||||
|   try { | ||||
|     const identity = await testClient.getIdentityByToken('test'); | ||||
|     console.log('✅ Identity retrieved successfully:'); | ||||
|     console.log(`  - Identity exists: ${!!identity}`); | ||||
|     if (identity) { | ||||
|       console.log(`  - Identity data:`, JSON.stringify(identity, null, 2)); | ||||
|     } | ||||
|     expect(identity).toBeTruthy(); | ||||
|   } catch (error) { | ||||
|     console.error('❌ Failed to get identity:'); | ||||
|     console.error(`  - Error message: ${error.message}`); | ||||
|     console.error(`  - Error stack:`, error.stack); | ||||
|     throw error; | ||||
|   } | ||||
| }); | ||||
|  | ||||
| let image: Image; | ||||
| tap.test('should create and upload an image', async () => { | ||||
|   image = await testClient.image.createImage({ | ||||
|     name: 'test', | ||||
|     description: 'test' | ||||
|   }); | ||||
|   console.log('created image: ', image); | ||||
|   expect(image).toBeInstanceOf(Image); | ||||
|   console.log('🔵 Test: Creating and uploading image...'); | ||||
|   console.log(`  - Image name: 'test'`); | ||||
|   console.log(`  - Image description: 'test'`); | ||||
|    | ||||
|   try { | ||||
|     image = await testClient.image.createImage({ | ||||
|       name: 'test', | ||||
|       description: 'test' | ||||
|     }); | ||||
|     console.log('✅ Image created successfully:'); | ||||
|     console.log(`  - Image ID: ${image?.id}`); | ||||
|     console.log(`  - Image data:`, image); | ||||
|     expect(image).toBeInstanceOf(Image); | ||||
|   } catch (error) { | ||||
|     console.error('❌ Failed to create image:'); | ||||
|     console.error(`  - Error message: ${error.message}`); | ||||
|     console.error(`  - Error stack:`, error.stack); | ||||
|     throw error; | ||||
|   } | ||||
| }) | ||||
|  | ||||
| tap.test('should upload an image version', async () => { | ||||
|   const imageStream = await helpers.getAlpineImageReadableStream(); | ||||
|  | ||||
|   await image.pushImageVersion('v1.0.0', imageStream); | ||||
|   console.log('🔵 Test: Uploading image version...'); | ||||
|   console.log(`  - Version: 'v1.0.0'`); | ||||
|   console.log(`  - Image exists: ${!!image}`); | ||||
|   console.log(`  - Image ID: ${image?.id}`); | ||||
|    | ||||
|   try { | ||||
|     const imageStream = await helpers.getAlpineImageReadableStream(); | ||||
|     console.log('  - Image stream obtained successfully'); | ||||
|      | ||||
|     await image.pushImageVersion('v1.0.0', imageStream); | ||||
|     console.log('✅ Image version uploaded successfully'); | ||||
|   } catch (error) { | ||||
|     console.error('❌ Failed to upload image version:'); | ||||
|     console.error(`  - Error message: ${error.message}`); | ||||
|     console.error(`  - Error stack:`, error.stack); | ||||
|     throw error; | ||||
|   } | ||||
| }); | ||||
|  | ||||
| tap.test('should stop the apiclient', async (toolsArg) => { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user