|
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' };
|
@@ -428,4 +428,26 @@ describe('rdme openapi upload', () => {
|
428 | 428 | fileMock.done();
|
429 | 429 | });
|
430 | 430 | });
|
| 431 | + |
| 432 | + describe('given that the confirm overwrite flag is passed', () => { |
| 433 | + it('should overwrite an existing API definition without asking for confirmation', async () => { |
| 434 | + const mock = getAPIv2Mock({ authorization: `Bearer ${key}` }) |
| 435 | + .get(`/versions/${version}/apis`) |
| 436 | + .reply(200, { data: [{ filename: slugifiedFilename }] }) |
| 437 | + .put(`/versions/${version}/apis/${slugifiedFilename}`, body => |
| 438 | + body.match(`form-data; name="schema"; filename="${slugifiedFilename}"`), |
| 439 | + ) |
| 440 | + .reply(200, { |
| 441 | + data: { |
| 442 | + upload: { status: 'done' }, |
| 443 | + uri: `/versions/${version}/apis/${slugifiedFilename}`, |
| 444 | + }, |
| 445 | + }); |
| 446 | + |
| 447 | + const result = await run(['--version', version, filename, '--key', key, '--confirm-overwrite']); |
| 448 | + expect(result.stdout).toContain('was successfully updated in ReadMe!'); |
| 449 | + |
| 450 | + mock.done(); |
| 451 | + }); |
| 452 | + }); |
431 | 453 | });
|
0 commit comments