|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Red Hat. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | +import * as sinon from 'sinon'; |
| 6 | +import * as chai from 'chai'; |
| 7 | +import * as sinonChai from 'sinon-chai'; |
| 8 | +import * as SchemaService from '../src/languageservice/services/yamlSchemaService'; |
| 9 | +import { parse } from '../src/languageservice/parser/yamlParser07'; |
| 10 | + |
| 11 | +const expect = chai.expect; |
| 12 | +chai.use(sinonChai); |
| 13 | + |
| 14 | +describe('YAML Schema Service', () => { |
| 15 | + const sandbox = sinon.createSandbox(); |
| 16 | + afterEach(() => { |
| 17 | + sandbox.restore(); |
| 18 | + }); |
| 19 | + |
| 20 | + describe('Schema for resource', () => { |
| 21 | + let requestServiceMock: sinon.SinonSpy; |
| 22 | + |
| 23 | + beforeEach(() => { |
| 24 | + requestServiceMock = sandbox.fake.resolves(undefined); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should handle inline schema http url', () => { |
| 28 | + const documentContent = `# yaml-language-server: $schema=http://json-schema.org/draft-07/schema# anothermodeline=value\n`; |
| 29 | + const content = `${documentContent}\n---\n- `; |
| 30 | + const yamlDock = parse(content); |
| 31 | + |
| 32 | + const service = new SchemaService.YAMLSchemaService(requestServiceMock); |
| 33 | + service.getSchemaForResource('', yamlDock.documents[0]); |
| 34 | + |
| 35 | + expect(requestServiceMock).calledOnceWith('http://json-schema.org/draft-07/schema#'); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should handle inline schema https url', () => { |
| 39 | + const documentContent = `# yaml-language-server: $schema=https://json-schema.org/draft-07/schema# anothermodeline=value\n`; |
| 40 | + const content = `${documentContent}\n---\n- `; |
| 41 | + const yamlDock = parse(content); |
| 42 | + |
| 43 | + const service = new SchemaService.YAMLSchemaService(requestServiceMock); |
| 44 | + service.getSchemaForResource('', yamlDock.documents[0]); |
| 45 | + |
| 46 | + expect(requestServiceMock).calledOnceWith('https://json-schema.org/draft-07/schema#'); |
| 47 | + }); |
| 48 | + }); |
| 49 | +}); |
0 commit comments