Skip to content

Commit

Permalink
add test for getLightningUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
midigofrank committed Jul 17, 2024
1 parent 960f293 commit a1cebb2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/deploy/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DeployConfig, ProjectPayload } from './types';
import { DeployError } from './deployError';

const getLightningUrl = (
export const getLightningUrl = (
config: DeployConfig,
path: string = '',
snapshots?: string[]
Expand Down
36 changes: 36 additions & 0 deletions packages/deploy/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { render } from '@inquirer/testing';
import { input } from '@inquirer/prompts';
import test from 'ava';
import { DeployConfig } from '../src/types';
import { getLightningUrl } from '../src/client';

test('renders a confirmation', async (t) => {
const { answer, events, getScreen } = await render(input, {
Expand All @@ -14,3 +16,37 @@ test('renders a confirmation', async (t) => {

t.is(await answer, 'John');
});

test('getLightningUrl adds snapshots correctly to the URL', async (t) => {
const config: DeployConfig = {
endpoint: 'http://localhost',
apiKey: 'test-api-key',
specPath: './project.yaml',
statePath: './state.json',
requireConfirmation: false,
dryRun: false,
};

const projectId = 'test-project';
const snapshots = ['snapshot1', 'snapshot2'];

const expectedUrl =
'http://localhost/api/provision/test-project?snapshots%5B%5D=snapshot1&snapshots%5B%5D=snapshot2';
t.is(getLightningUrl(config, projectId, snapshots).toString(), expectedUrl);
});

test('getLightningUrl returns the correct URL when no snapshot is provided', async (t) => {
const config: DeployConfig = {
endpoint: 'http://localhost',
apiKey: 'test-api-key',
specPath: './project.yaml',
statePath: './state.json',
requireConfirmation: false,
dryRun: false,
};

const projectId = 'test-project';

const expectedUrl = 'http://localhost/api/provision/test-project?';
t.is(getLightningUrl(config, projectId).toString(), expectedUrl);
});

0 comments on commit a1cebb2

Please sign in to comment.