Skip to content

Commit 66ec6ff

Browse files
philippfrommebarmac
authored andcommitted
test: add integration tests for OOTB connector templates
Co-authored-by: Maciej Barelkowski <[email protected]>
1 parent 876583e commit 66ec6ff

File tree

6 files changed

+156
-2
lines changed

6 files changed

+156
-2
lines changed

.github/workflows/INTEGRATION.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: INTEGRATION
2+
on: [ push, pull_request ]
3+
jobs:
4+
Build:
5+
runs-on: ubuntu-latest
6+
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v4
10+
- name: Use Node.js
11+
uses: actions/setup-node@v4
12+
with:
13+
node-version: 20
14+
cache: 'npm'
15+
- name: Install dependencies
16+
run: npm ci
17+
- name: Build
18+
run: npm run build
19+
- name: Fetch connector templates
20+
run: npm run fetch:connector-templates
21+
- name: Test
22+
run: npm run test:integration

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ dist/
33
coverage/
44
.idea
55
*.iml
6-
.DS_Store
6+
.DS_Store
7+
packages/**/test/integration/*.json

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"lint": "eslint packages",
77
"test": "lerna run test",
8+
"test:integration": "lerna run test:integration",
89
"dev": "run-s build \"lerna-dev -- {@}\" -- ",
910
"lerna-dev": "lerna run dev --stream --scope",
1011
"build": "lerna run build --parallel --stream",
@@ -16,7 +17,8 @@
1617
"lerna-publish:dry": "lerna version --no-git-tag-version --no-push",
1718
"release": "run-s build test lerna-publish",
1819
"release:alpha": "run-s build test lerna-publish:alpha",
19-
"release:dry": "run-s build test lerna-publish:dry"
20+
"release:dry": "run-s build test lerna-publish:dry",
21+
"fetch:connector-templates": "node tasks/fetch-connector-templates.js"
2022
},
2123
"repository": {
2224
"type": "git",

packages/zeebe-element-templates-json-schema/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
],
88
"scripts": {
99
"test": "mocha --reporter=spec --recursive test/spec",
10+
"test:integration": "mocha --reporter=spec --recursive test/integration",
1011
"dev": "npm run test -- --watch",
1112
"all": "run-s build test",
1213
"build": "run-s build:error-messages build:schema",
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { expect } = require('chai');
2+
3+
const schema = require('../../resources/schema.json');
4+
5+
const errorMessages = require('../../resources/error-messages.json');
6+
7+
const {
8+
createValidator
9+
} = require('../../../element-templates-json-schema-shared/test/helpers');
10+
11+
const validator = createValidator(schema, errorMessages);
12+
13+
const templates = require('./ootb-connector-templates.json');
14+
15+
function validateTemplate(template) {
16+
17+
const valid = validator(template);
18+
19+
const errors = validator.errors;
20+
21+
return {
22+
valid,
23+
errors
24+
};
25+
}
26+
27+
describe('validation', function() {
28+
29+
templates.forEach(function(template) {
30+
31+
it(`should validate template <${ template.name }>`, async function() {
32+
33+
// when
34+
const {
35+
valid,
36+
errors
37+
} = validateTemplate(template);
38+
39+
if (!valid) {
40+
console.error(`Validation errors for template <${ template.name }>:`, errors);
41+
}
42+
43+
// then
44+
expect(valid).to.be.true;
45+
expect(errors).to.be.null;
46+
});
47+
48+
});
49+
50+
});

tasks/fetch-connector-templates.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
3+
* under one or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information regarding copyright
5+
* ownership.
6+
*
7+
* Camunda licenses this file to you under the MIT; you may not use this file
8+
* except in compliance with the MIT License.
9+
*/
10+
11+
import { writeFileSync as writeFile } from 'fs';
12+
import { resolve as pathResolve } from 'path';
13+
14+
const URL = 'https://marketplace.cloud.camunda.io/api/v1/ootb-connectors';
15+
16+
const templates = await fetchTemplates();
17+
18+
writeFile(
19+
pathResolve('packages/zeebe-element-templates-json-schema/test/integration/ootb-connector-templates.json'),
20+
JSON.stringify(templates, null, 2)
21+
);
22+
23+
/**
24+
* Fetch OOTB connector templates from the Camunda Marketplace.
25+
*
26+
* @returns {Promise<Template[]>} templates
27+
*/
28+
async function fetchTemplates() {
29+
console.info('Fetching and updating templates');
30+
31+
let response = await fetch(URL);
32+
33+
if (!response.ok) {
34+
console.warn(`Failed to fetch templates from ${ URL } (HTTP ${ response.status })`);
35+
36+
return [];
37+
}
38+
39+
/** @type {TemplatesByIdMetadata} */
40+
const templatesByIdMetadata = await response.json();
41+
42+
const tasks = [];
43+
44+
for (const id in templatesByIdMetadata) {
45+
const templatesMetadata = templatesByIdMetadata[ id ];
46+
47+
for (const templateMetadata of templatesMetadata) {
48+
tasks.push(fetchTemplate(templateMetadata, id));
49+
}
50+
}
51+
52+
return (await Promise.all(tasks)).filter(template => template !== null);
53+
}
54+
55+
async function fetchTemplate(templateMetadata, id) {
56+
const { ref } = templateMetadata;
57+
58+
const response = await fetch(ref);
59+
60+
if (!response.ok) {
61+
console.warn(`Failed to fetch template ${ id } version ${ templateMetadata.version } from ${ ref } (HTTP ${ response.status })`);
62+
63+
return null;
64+
}
65+
66+
try {
67+
const templateText = await response.text();
68+
let templateJson = JSON.parse(templateText);
69+
70+
console.info(`Fetched template ${ id } version ${ templateMetadata.version } from ${ ref }`);
71+
72+
return templateJson;
73+
} catch (error) {
74+
console.warn(`Failed to parse template ${ id } version ${ templateMetadata.version } fetched from ${ ref }`, error);
75+
76+
return null;
77+
}
78+
}

0 commit comments

Comments
 (0)