|
1 | 1 | import nock from 'nock'; |
2 | 2 | import prompts from 'prompts'; |
3 | 3 | import slugify from 'slugify'; |
4 | | -import { describe, beforeAll, beforeEach, afterEach, it, expect } from 'vitest'; |
| 4 | +import { afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest'; |
5 | 5 |
|
6 | 6 | import Command from '../../../src/commands/openapi/upload.js'; |
7 | 7 | import petstore from '../../__fixtures__/petstore-simple-weird-version.json' with { type: 'json' }; |
@@ -401,4 +401,26 @@ describe('rdme openapi upload', () => { |
401 | 401 | fileMock.done(); |
402 | 402 | }); |
403 | 403 | }); |
| 404 | + |
| 405 | + describe('given that the confirm overwrite flag is passed', () => { |
| 406 | + it('should overwrite an existing API definition without asking for confirmation', async () => { |
| 407 | + const mock = getAPIv2Mock({ authorization: `Bearer ${key}` }) |
| 408 | + .get(`/versions/${version}/apis`) |
| 409 | + .reply(200, { data: [{ filename: slugifiedFilename }] }) |
| 410 | + .put(`/versions/${version}/apis/${slugifiedFilename}`, body => |
| 411 | + body.match(`form-data; name="schema"; filename="${slugifiedFilename}"`), |
| 412 | + ) |
| 413 | + .reply(200, { |
| 414 | + data: { |
| 415 | + upload: { status: 'done' }, |
| 416 | + uri: `/versions/${version}/apis/${slugifiedFilename}`, |
| 417 | + }, |
| 418 | + }); |
| 419 | + |
| 420 | + const result = await run(['--version', version, filename, '--key', key, '--confirm-overwrite']); |
| 421 | + expect(result.stdout).toContain('was successfully updated in ReadMe!'); |
| 422 | + |
| 423 | + mock.done(); |
| 424 | + }); |
| 425 | + }); |
404 | 426 | }); |
0 commit comments