diff --git a/tests/channels.ts b/tests/channels.ts new file mode 100644 index 00000000..bde5a8b3 --- /dev/null +++ b/tests/channels.ts @@ -0,0 +1,12 @@ +import assert from 'node:assert'; +import test from 'node:test'; +import type {Hop} from '../src'; + +// Todo: add other tests + +export function channelsTests(hop: Hop) { + test('It gets all channels', async () => { + const channels = await hop.channels.getAll(); + assert.ok(Array.isArray(channels)); + }); +} diff --git a/tests/fleet.ts b/tests/fleet.ts new file mode 100644 index 00000000..e8e0296a --- /dev/null +++ b/tests/fleet.ts @@ -0,0 +1,56 @@ +import assert from 'node:assert'; +import test from 'node:test'; +import {FleetSchedulingState, type Hop} from '../src'; + +export function fleetTests(hop: Hop) { + let createdNode: Awaited>['node']; + let nodesLength: number; + + test('It can create fleet node', async () => { + const randomNodeName = `test-node-${Math.random() + .toString(36) + .substring(7)}`; + const {node, token} = await hop.fleet.createNode( + randomNodeName, + FleetSchedulingState.SCHEDULABLE, + ); + + assert.ok(node); + assert.ok(token.startsWith('fleet_token')); + assert.equal(node.name, randomNodeName); + assert.equal(node.scheduling_state, FleetSchedulingState.SCHEDULABLE); + createdNode = node; + }); + + test('It can regenerate node token', async () => { + const token = await createdNode.regenerateToken(); + + assert.ok(token.startsWith('fleet_token')); + }); + + test('It can get all nodes', async () => { + const nodes = await hop.fleet.getNodes(); + + assert.ok(nodes.length > 0); + assert.ok(nodes.find(n => createdNode.id === n.id)); + nodesLength = nodes.length; + }); + + test('It can edit node', async () => { + const node = await createdNode.editNode({ + schedulingState: FleetSchedulingState.UNSCHEDULABLE, + }); + + assert.ok(node); + assert.equal(node.scheduling_state, FleetSchedulingState.UNSCHEDULABLE); + }); + + test('It can delete a node', async () => { + assert.doesNotThrow(async () => { + await createdNode.deleteNode(); + + const nodes = await hop.fleet.getNodes(); + assert.ok(nodesLength - 1 === nodes.length); + }); + }); +} diff --git a/tests/index.ts b/tests/index.ts index 71e98624..b01a3e1e 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -4,8 +4,12 @@ import assert from 'node:assert/strict'; import {test} from 'node:test'; import {Hop, id, validateId} from '../src/index.ts'; -import {webhookTests} from './projects/webhooks.ts'; +import {channelsTests} from './channels.ts'; +import {fleetTests} from './fleet.ts'; import {membersTest} from './projects/members.ts'; +import {webhookTests} from './projects/webhooks.ts'; + +const SDK_TESTS = [webhookTests, membersTest, fleetTests, channelsTests]; // @ts-expect-error This is usually injected by tsup globalThis.TSUP_IS_NODE = true; @@ -60,12 +64,6 @@ test('It validates that the token is valid', () => { assert(validateId('ptk_testing', 'ptk'), "Couldn't validate Project Token"); }); -// Project Tests -webhookTests(hop); -membersTest(hop); - -// Todo: Move this to a separate folder + add channel tokens and other tests. -test('It gets all channels', async () => { - const channels = await hop.channels.getAll(); - assert.ok(Array.isArray(channels)); -}); +for (const SDKTest of SDK_TESTS) { + SDKTest(hop); +}