fix(client): update request handling and typings for current smartrequest and OpenAPI output
This commit is contained in:
+40
-11
@@ -1,24 +1,49 @@
|
||||
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as hetznercloud from '../ts/index.js';
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
const testQenv = new qenv.Qenv('./', './.nogit/');
|
||||
|
||||
let testAccount: hetznercloud.HetznerAccount;
|
||||
let testAccount: hetznercloud.HetznerAccount | undefined;
|
||||
let liveApiAvailable = false;
|
||||
let liveApiSkipReason = 'HETZNER_API_TOKEN has not been validated.';
|
||||
|
||||
tap.test('should create a valid hetzer account', async () => {
|
||||
testAccount = new hetznercloud.HetznerAccount(
|
||||
await testQenv.getEnvVarOnDemand('HETZNER_API_TOKEN')
|
||||
);
|
||||
tap.test('should create a valid hetzer account', async (toolsArg) => {
|
||||
const token = await testQenv.getEnvVarOnDemand('HETZNER_API_TOKEN');
|
||||
if (!token) {
|
||||
liveApiSkipReason = 'HETZNER_API_TOKEN is not configured.';
|
||||
toolsArg.skip(liveApiSkipReason);
|
||||
return;
|
||||
}
|
||||
testAccount = new hetznercloud.HetznerAccount(token);
|
||||
expect(testAccount).toBeInstanceOf(hetznercloud.HetznerAccount);
|
||||
});
|
||||
|
||||
tap.test('should be able to list all servers', async () => {
|
||||
const servers = await testAccount.getServers();
|
||||
tap.test('should be able to list all servers', async (toolsArg) => {
|
||||
if (!testAccount) {
|
||||
toolsArg.skip(liveApiSkipReason);
|
||||
return;
|
||||
}
|
||||
const account = testAccount;
|
||||
const tokenCheckResponse = await account.request('GET', '/servers', {});
|
||||
if (tokenCheckResponse.statusCode === 401 || tokenCheckResponse.statusCode === 403) {
|
||||
liveApiSkipReason = 'HETZNER_API_TOKEN was rejected by the Hetzner API.';
|
||||
toolsArg.skip(liveApiSkipReason);
|
||||
return;
|
||||
}
|
||||
if (tokenCheckResponse.statusCode < 200 || tokenCheckResponse.statusCode >= 300) {
|
||||
throw new Error(`Hetzner API returned status ${tokenCheckResponse.statusCode}`);
|
||||
}
|
||||
liveApiAvailable = true;
|
||||
const servers = await account.getServers();
|
||||
expect(servers).toBeArray();
|
||||
console.log(JSON.stringify(servers, null, 2));
|
||||
});
|
||||
|
||||
const testserver = tap.test('should be able to create a server', async (toolsArg) => {
|
||||
if (!liveApiAvailable || !testAccount) {
|
||||
toolsArg.skip(liveApiSkipReason);
|
||||
return;
|
||||
}
|
||||
const newServer = await testAccount.createServer({
|
||||
name: 'testserver',
|
||||
location: 'nbg1',
|
||||
@@ -33,10 +58,14 @@ const testserver = tap.test('should be able to create a server', async (toolsArg
|
||||
return newServer;
|
||||
});
|
||||
|
||||
tap.test('should be able to delete a server', async () => {
|
||||
tap.test('should be able to delete a server', async (toolsArg) => {
|
||||
if (!liveApiAvailable) {
|
||||
toolsArg.skip(liveApiSkipReason);
|
||||
return;
|
||||
}
|
||||
const testServer: hetznercloud.HetznerServer =
|
||||
await (testserver.testResultPromise as Promise<hetznercloud.HetznerServer>);
|
||||
await testServer.delete();
|
||||
await testServer.delete();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
export default tap.start();
|
||||
|
||||
Reference in New Issue
Block a user