Skip to content

Commit

Permalink
devex/chore: fleet tests + move channels into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
Looskie committed Nov 18, 2023
1 parent 5a728fd commit dd6fd05
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 10 deletions.
12 changes: 12 additions & 0 deletions tests/channels.ts
Original file line number Diff line number Diff line change
@@ -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));
});
}
56 changes: 56 additions & 0 deletions tests/fleet.ts
Original file line number Diff line number Diff line change
@@ -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<ReturnType<typeof hop.fleet.createNode>>['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);
});
});
}
18 changes: 8 additions & 10 deletions tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

0 comments on commit dd6fd05

Please sign in to comment.