2024-06-05 12:13:03 +00:00
|
|
|
import { tap, expect } from '@push.rocks/tapbundle';
|
2024-10-16 12:35:38 +00:00
|
|
|
import * as helpers from './helpers/index.js';
|
2024-06-05 12:13:03 +00:00
|
|
|
|
2024-10-16 12:35:38 +00:00
|
|
|
import * as cloudly from '../ts/index.js';
|
2024-06-05 12:13:03 +00:00
|
|
|
import * as cloudlyApiClient from '../ts_apiclient/index.js';
|
2024-10-16 12:35:38 +00:00
|
|
|
import { Image } from '../ts_apiclient/classes.image.js';
|
2024-06-05 12:13:03 +00:00
|
|
|
|
2024-10-16 12:35:38 +00:00
|
|
|
let testCloudly: cloudly.Cloudly;
|
2024-06-05 12:13:03 +00:00
|
|
|
let testClient: cloudlyApiClient.CloudlyApiClient;
|
|
|
|
|
2024-10-16 12:35:38 +00:00
|
|
|
tap.preTask('should start cloudly', async () => {
|
|
|
|
testCloudly = await helpers.createCloudly();
|
|
|
|
await testCloudly.start();
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.preTask('should create a new machine user for testing', async () => {
|
|
|
|
const machineUser = new testCloudly.authManager.CUser();
|
|
|
|
machineUser.id = await testCloudly.authManager.CUser.getNewId();
|
|
|
|
machineUser.data = {
|
|
|
|
type: 'machine',
|
|
|
|
username: 'test',
|
|
|
|
password: 'test',
|
|
|
|
tokens: [{
|
|
|
|
token: 'test',
|
|
|
|
expiresAt: Date.now() + 3600 * 1000 * 24 * 365,
|
|
|
|
assignedRoles: ['admin'],
|
|
|
|
}],
|
|
|
|
role: 'admin',
|
|
|
|
};
|
|
|
|
await machineUser.save();
|
|
|
|
});
|
|
|
|
|
2024-06-05 12:13:03 +00:00
|
|
|
tap.test('should create a new cloudlyApiClient', async () => {
|
|
|
|
testClient = new cloudlyApiClient.CloudlyApiClient({
|
|
|
|
registerAs: 'api',
|
2024-11-06 16:19:43 +00:00
|
|
|
cloudlyUrl: `http://${helpers.testCloudlyConfig.publicUrl}:${helpers.testCloudlyConfig.publicPort}`,
|
2024-06-05 12:13:03 +00:00
|
|
|
});
|
2024-10-16 12:35:38 +00:00
|
|
|
await testClient.start();
|
2024-06-05 12:13:03 +00:00
|
|
|
expect(testClient).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2024-10-16 12:35:38 +00:00
|
|
|
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();
|
|
|
|
})
|
|
|
|
|
2024-08-25 12:29:26 +00:00
|
|
|
tap.test('should get an identity', async () => {
|
2024-10-16 12:35:38 +00:00
|
|
|
const identity = await testClient.getIdentityByToken('test');
|
2024-08-25 12:29:26 +00:00
|
|
|
expect(identity).toBeTruthy();
|
2024-10-16 12:35:38 +00:00
|
|
|
console.log(identity);
|
2024-08-25 12:29:26 +00:00
|
|
|
});
|
|
|
|
|
2024-10-16 12:35:38 +00:00
|
|
|
let image: Image;
|
|
|
|
tap.test('should create and upload an image', async () => {
|
|
|
|
image = await testClient.images.createImage({
|
|
|
|
name: 'test',
|
|
|
|
description: 'test'
|
|
|
|
});
|
|
|
|
console.log('created image: ', image);
|
|
|
|
expect(image).toBeInstanceOf(Image);
|
2024-06-05 12:13:03 +00:00
|
|
|
})
|
|
|
|
|
2024-10-16 12:35:38 +00:00
|
|
|
tap.test('should upload an image version', async () => {
|
|
|
|
const imageStream = await helpers.getAlpineImageReadableStream();
|
|
|
|
|
|
|
|
await image.pushImageVersion('v1.0.0', imageStream);
|
|
|
|
});
|
|
|
|
|
2024-08-25 12:29:26 +00:00
|
|
|
tap.test('should stop the apiclient', async (toolsArg) => {
|
2024-10-16 12:35:38 +00:00
|
|
|
await toolsArg.delayFor(10000);
|
2024-11-06 02:56:46 +00:00
|
|
|
await helpers.stopCloudly();
|
2024-06-05 12:13:03 +00:00
|
|
|
await testClient.stop();
|
2024-10-16 12:35:38 +00:00
|
|
|
await testCloudly.stop();
|
2024-06-05 12:13:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
export default tap.start();
|