Skip to content

Commit

Permalink
temp: why isn't this working 🧐
Browse files Browse the repository at this point in the history
I've isolated a test here to demonstrate some weirdness going on... basically the generatePrompts() function isn't being called from this test at all, but it works fine when I run the command locally
  • Loading branch information
kanadgupta committed Aug 17, 2022
1 parent 6bb35e6 commit 9c529f6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
17 changes: 9 additions & 8 deletions __tests__/cmds/openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import SwaggerCommand from '../../src/cmds/swagger';
import APIError from '../../src/lib/apiError';
import getAPIMock from '../helpers/get-api-mock';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const promptHandler = require('../../src/lib/prompts');
// // eslint-disable-next-line @typescript-eslint/no-var-requires
// const promptHandler = require('../../src/lib/prompts');

const openapi = new OpenAPICommand();
const swagger = new SwaggerCommand();
Expand Down Expand Up @@ -428,19 +428,20 @@ describe('rdme openapi', () => {
return mock.done();
});

it('should request a version list if version is not found', async () => {
promptHandler.generatePrompts.mockResolvedValue({
option: 'create',
newVersion: '1.0.1',
});
it.only('should request a version list if version is not found', async () => {
// promptHandler.generatePrompts.mockResolvedValue({
// option: 'create',
// newVersion: '1.0.1',
// });

const registryUUID = getRandomRegistryId();

const mock = getAPIMock()
.get('/api/v1/version')
.basicAuth({ user: key })
.reply(200, [{ version: '1.0.0' }])
.post('/api/v1/version')
// This nock is failing because promptHandler.generatePrompts() isn't being called in this test
.post('/api/v1/version', { from: '1.0.0', version: '1.0.1', is_stable: false })
.basicAuth({ user: key })
.reply(200, { from: '1.0.0', version: '1.0.1' })
.post('/api/v1/api-registry', body => body.match('form-data; name="spec"'))
Expand Down
1 change: 1 addition & 0 deletions src/lib/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ParsedDocs = {
};

export function generatePrompts(versionList: VersionList, selectOnly = false) {
console.log("this function should be called... but it isn't and I have no idea why :sob:");
return [
{
type: selectOnly ? null : 'select',
Expand Down
16 changes: 11 additions & 5 deletions src/lib/versionSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ export async function getProjectVersion(versionFlag: string, key: string, allowN

if (option === 'update') return versionSelection;

console.log('newVersion:', newVersion);

const body = JSON.stringify({
from: versionList[0].version,
version: newVersion,
is_stable: false,
});

console.log('body:', body);

const newVersionFromApi = await fetch(`${config.get('host')}/api/v1/version`, {
method: 'post',
headers: cleanHeaders(key, new Headers({ 'Content-Type': 'application/json' })),
body: JSON.stringify({
from: versionList[0].version,
version: newVersion,
is_stable: false,
}),
body,
})
.then(res => handleRes(res))
.then(res => res.version);
Expand Down

0 comments on commit 9c529f6

Please sign in to comment.