From 9c529f6c61e72ee75a3c6c98ed0a2142b852a6c9 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 16 Aug 2022 20:21:29 -0500 Subject: [PATCH] =?UTF-8?q?temp:=20why=20isn't=20this=20working=20?= =?UTF-8?q?=F0=9F=A7=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- __tests__/cmds/openapi.test.ts | 17 +++++++++-------- src/lib/prompts.ts | 1 + src/lib/versionSelect.ts | 16 +++++++++++----- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/__tests__/cmds/openapi.test.ts b/__tests__/cmds/openapi.test.ts index 96acc5671..2bde3547e 100644 --- a/__tests__/cmds/openapi.test.ts +++ b/__tests__/cmds/openapi.test.ts @@ -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(); @@ -428,11 +428,11 @@ 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(); @@ -440,7 +440,8 @@ describe('rdme openapi', () => { .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"')) diff --git a/src/lib/prompts.ts b/src/lib/prompts.ts index 6f6a85a7e..7dbaed4ce 100644 --- a/src/lib/prompts.ts +++ b/src/lib/prompts.ts @@ -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', diff --git a/src/lib/versionSelect.ts b/src/lib/versionSelect.ts index aa8080e3d..418ac73d1 100644 --- a/src/lib/versionSelect.ts +++ b/src/lib/versionSelect.ts @@ -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);