Skip to content

Commit

Permalink
test(ls): add test for ref validation of valid async spec
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Sep 29, 2023
1 parent a4cdb36 commit d9b476a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
33 changes: 33 additions & 0 deletions packages/apidom-ls/test/fixtures/deref/valid-async.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
asyncapi: '2.6.0'
info:
version: '1.0.0'
title: 'streetlights'
channels:
test:
publish:
operationId: receiveLightMeasurement
message:
$ref: '#/components/messages/lightMeasured'
components:
messages:
lightMeasured:
name: lightMeasured
title: Light measured
summary: Inform about environmental lighting conditions of a particular streetlight.
contentType: application/json
payload:
$ref: "#/components/schemas/lightMeasuredPayload"
schemas:
lightMeasuredPayload:
type: object
properties:
lumens:
type: integer
minimum: 0
description: Light intensity measured in lumens.
sentAt:
$ref: "#/components/schemas/sentAt"
sentAt:
type: string
format: date-time
description: Date and time when the message was sent.
36 changes: 35 additions & 1 deletion packages/apidom-ls/test/validate-references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const spec = fs.readFileSync(path.join(__dirname, 'fixtures', 'deref', 'invalid.
const specValid = fs
.readFileSync(path.join(__dirname, 'fixtures', 'deref', 'valid-same-ref.json'))
.toString();
const specValidAsync = fs
.readFileSync(path.join(__dirname, 'fixtures', 'deref', 'valid-async.yaml'))
.toString();

describe('reference validation', function () {
const lsContext: LanguageServiceContext = {
Expand All @@ -30,7 +33,7 @@ describe('reference validation', function () {

const languageService: LanguageService = getLanguageService(lsContext);

context('given doc with invalid references', function () {
context('given doc with references', function () {
const httpPort = 8123;
let httpServer: ServerTerminable;

Expand Down Expand Up @@ -355,5 +358,36 @@ describe('reference validation', function () {
}) as Diagnostic[],
);
});
specify('should validate valid async spec with apidom-reference', async function () {
this.timeout(10000);
const validationContext: ValidationContext = {
comments: DiagnosticSeverity.Error,
maxNumberOfProblems: 100,
relatedInformation: false,
referenceValidationMode: ReferenceValidationMode.APIDOM_INDIRECT_EXTERNAL,
};

const doc: TextDocument = TextDocument.create(
'foo://bar/specValidAsync.json',
'json',
0,
specValidAsync,
);

const valRes = await languageService.doValidation(doc, validationContext);
const exp: Diagnostic[] = [];
assert.deepEqual(
valRes.map((value) => {
// eslint-disable-next-line no-param-reassign
value.code = 'test';
return value;
}),
exp.map((value) => {
// eslint-disable-next-line no-param-reassign
value.code = 'test';
return value;
}) as Diagnostic[],
);
});
});
});

0 comments on commit d9b476a

Please sign in to comment.