Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to check Jira SourceJSON schema required fields for each stream #1470

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions sources/jira-source/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from 'faros-airbyte-cdk';
import {FarosClient} from 'faros-js-client';
import fs from 'fs-extra';
import {Dictionary} from 'ts-essentials';
import VError from 'verror';

import {FarosIssuePullRequests} from '../lib/streams/faros_issue_pull_requests';
Expand Down Expand Up @@ -187,6 +188,46 @@ describe('index', () => {
.mockResolvedValue(readTestResourceFile('sprint_report.json')),
});

test('streams - json schema fields', async () => {
const source = new sut.JiraSource(logger);
const streams = source.streams(config);

const validateFieldInSchema = (
field: string | string[],
schema: Dictionary<any>
) => {
if (Array.isArray(field)) {
let nestedField = schema;
for (const subField of field) {
expect(nestedField).toHaveProperty(subField);
nestedField = nestedField[subField].properties;
}
} else {
expect(schema).toHaveProperty(field);
}
};

for (const stream of streams) {
const jsonSchema = stream.getJsonSchema().properties;
const primaryKey = stream.primaryKey;
const cursorField = stream.cursorField;

// Validate primaryKey is in jsonSchema
if (primaryKey) {
if (Array.isArray(primaryKey)) {
for (const key of primaryKey) {
validateFieldInSchema(key, jsonSchema);
}
} else {
validateFieldInSchema(primaryKey, jsonSchema);
}
}

// Validate cursorField is in jsonSchema
validateFieldInSchema(cursorField, jsonSchema);
}
});

test('streams - issue_pull_requests', async () => {
await testStream(
0,
Expand Down
Loading