|
5 | 5 | import * as assert from 'assert'; |
6 | 6 | import * as sinon from 'sinon'; |
7 | 7 | import * as vscode from 'vscode'; |
8 | | -import { registerCodeActions } from '../code-actions'; |
| 8 | +import { registerCodeActions, extractSchemaFilename } from '../code-actions'; |
9 | 9 | import { getExtensionContext, createDevProxyInstall, getFixturePath } from './helpers'; |
10 | 10 | import { DiagnosticCodes } from '../constants'; |
11 | 11 | import { getDiagnosticCode, sleep } from '../utils'; |
@@ -533,3 +533,59 @@ suite('Code Action Provider Registration', () => { |
533 | 533 | registerCodeActions(contextWithInstall); |
534 | 534 | }); |
535 | 535 | }); |
| 536 | + |
| 537 | +suite('extractSchemaFilename', () => { |
| 538 | + test('should extract rc.schema.json from config file schema URL', () => { |
| 539 | + const url = 'https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.29.0/rc.schema.json'; |
| 540 | + assert.strictEqual(extractSchemaFilename(url), 'rc.schema.json'); |
| 541 | + }); |
| 542 | + |
| 543 | + test('should extract mockresponseplugin.mocksfile.schema.json from mocks file schema URL', () => { |
| 544 | + const url = 'https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/mockresponseplugin.mocksfile.schema.json'; |
| 545 | + assert.strictEqual(extractSchemaFilename(url), 'mockresponseplugin.mocksfile.schema.json'); |
| 546 | + }); |
| 547 | + |
| 548 | + test('should extract crudapiplugin.apifile.schema.json from CRUD API file schema URL', () => { |
| 549 | + const url = 'https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.1.0/crudapiplugin.apifile.schema.json'; |
| 550 | + assert.strictEqual(extractSchemaFilename(url), 'crudapiplugin.apifile.schema.json'); |
| 551 | + }); |
| 552 | + |
| 553 | + test('should extract rewriteplugin.rewritesfile.schema.json from rewrites file schema URL', () => { |
| 554 | + const url = 'https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.25.0/rewriteplugin.rewritesfile.schema.json'; |
| 555 | + assert.strictEqual(extractSchemaFilename(url), 'rewriteplugin.rewritesfile.schema.json'); |
| 556 | + }); |
| 557 | + |
| 558 | + test('should extract genericrandomerrorplugin.errorsfile.schema.json', () => { |
| 559 | + const url = 'https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/genericrandomerrorplugin.errorsfile.schema.json'; |
| 560 | + assert.strictEqual(extractSchemaFilename(url), 'genericrandomerrorplugin.errorsfile.schema.json'); |
| 561 | + }); |
| 562 | + |
| 563 | + test('should extract ratelimitingplugin.customresponsefile.schema.json', () => { |
| 564 | + const url = 'https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.0.0/ratelimitingplugin.customresponsefile.schema.json'; |
| 565 | + assert.strictEqual(extractSchemaFilename(url), 'ratelimitingplugin.customresponsefile.schema.json'); |
| 566 | + }); |
| 567 | + |
| 568 | + test('should return default rc.schema.json for URL without .schema.json', () => { |
| 569 | + const url = 'https://example.com/some/path/file.json'; |
| 570 | + assert.strictEqual(extractSchemaFilename(url), 'rc.schema.json'); |
| 571 | + }); |
| 572 | + |
| 573 | + test('should return default rc.schema.json for empty string', () => { |
| 574 | + assert.strictEqual(extractSchemaFilename(''), 'rc.schema.json'); |
| 575 | + }); |
| 576 | + |
| 577 | + test('should return default rc.schema.json for malformed URL', () => { |
| 578 | + const url = 'not-a-valid-url'; |
| 579 | + assert.strictEqual(extractSchemaFilename(url), 'rc.schema.json'); |
| 580 | + }); |
| 581 | + |
| 582 | + test('should handle schema URL from old microsoft org', () => { |
| 583 | + const url = 'https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.20.0/mockresponseplugin.schema.json'; |
| 584 | + assert.strictEqual(extractSchemaFilename(url), 'mockresponseplugin.schema.json'); |
| 585 | + }); |
| 586 | + |
| 587 | + test('should be case-insensitive for .schema.json extension', () => { |
| 588 | + const url = 'https://example.com/path/MyPlugin.SCHEMA.JSON'; |
| 589 | + assert.strictEqual(extractSchemaFilename(url), 'MyPlugin.SCHEMA.JSON'); |
| 590 | + }); |
| 591 | +}); |
0 commit comments