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

Allow sub-folders in pixel definitions #2

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 16 additions & 6 deletions bin/validate_schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,34 @@ const argv = yargs(hideBin(process.argv))

// 1) Validate common params and suffixes
const mainDir = argv.dirPath;
const pixelsDir = path.join(mainDir, 'pixels');
const commonParams = JSON5.parse(fs.readFileSync(`${mainDir}/common_params.json`));
const commonSuffixes = JSON5.parse(fs.readFileSync(`${mainDir}/common_suffixes.json`));
const validator = new DefinitionsValidator(commonParams, commonSuffixes);
logErrors('ERROR in common_params.json:', validator.validateCommonParamsDefinition());
logErrors('ERROR in common_suffixes.json:', validator.validateCommonSuffixesDefinition());

// 2) Validate pixels and params
const pixelsDir = path.join(mainDir, 'pixels');
function validateFile(file) {
console.log(`Validating pixels definition: ${file}`);
const pixelsDef = JSON5.parse(fs.readFileSync(path.join(pixelsDir, file)));
const pixelsDef = JSON5.parse(fs.readFileSync(file));
logErrors(`ERROR in ${file}:`, validator.validatePixelsDefinition(pixelsDef));
}

function validateFolder(folder) {
fs.readdirSync(folder).forEach((file) => {
nshuba marked this conversation as resolved.
Show resolved Hide resolved
const fullPath = path.join(folder, file);
if (fs.statSync(fullPath).isDirectory()) {
validateFolder(fullPath);
return;
}

validateFile(fullPath);
});
}

if (argv.file) {
validateFile(argv.file);
validateFile(path.join(pixelsDir, argv.file));
} else {
fs.readdirSync(pixelsDir).forEach((file) => {
validateFile(file);
});
validateFolder(pixelsDir);
}
18 changes: 11 additions & 7 deletions tests/integration_test.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { exec } from 'child_process';
import { expect } from 'chai';
import path from 'path';

const timeout = 5000;
const validDefsPath = path.join('tests', 'test_data', 'valid');
const invalidDefsPath = path.join('tests', 'test_data', 'invalid');
describe('Invalid defs', () => {
it('should output all required params', (done) => {
exec('npm run validate-ddg-pixel-defs tests/test_data/invalid', (error, _, stderr) => {
exec(`npm run validate-ddg-pixel-defs ${invalidDefsPath}`, (error, _, stderr) => {
const pixelPath = path.join(invalidDefsPath, 'pixels', 'pixels.json');
const expectedErrors = [
"ERROR in pixels.json: /invalid_pixel must have required property 'description'",
"ERROR in pixels.json: /invalid_pixel must have required property 'owners'",
"ERROR in pixels.json: /invalid_pixel must have required property 'triggers'",
`ERROR in ${pixelPath}: /invalid_pixel must have required property 'description'`,
`ERROR in ${pixelPath}: /invalid_pixel must have required property 'owners'`,
`ERROR in ${pixelPath}: /invalid_pixel must have required property 'triggers'`,
];

const errors = stderr.trim().split('\n');
Expand All @@ -22,7 +26,7 @@ describe('Invalid defs', () => {

describe('Valid defs', () => {
it('should exit normally', (done) => {
exec('npm run validate-ddg-pixel-defs tests/test_data/valid', (error, _, stderr) => {
exec(`npm run validate-ddg-pixel-defs ${validDefsPath}`, (error, _, stderr) => {
expect(stderr.length).to.equal(0);
expect(error).to.equal(null);

Expand All @@ -34,7 +38,7 @@ describe('Valid defs', () => {
describe('Invalid live pixel', () => {
it('should output extra property error', (done) => {
exec(
'npm run validate-ddg-live-pixel tests/test_data/valid test_pixels.json m.netp.tunnel.stop.failure /t/m_netp_tunnel_stop_failure_d_ios_phone?x=1',
`npm run validate-ddg-live-pixel ${validDefsPath} pixel_subfolder/test_pixels.json m.netp.tunnel.stop.failure /t/m_netp_tunnel_stop_failure_d_ios_phone?x=1`,
(error, _, stderr) => {
const expectedErrors = ["ERROR: must NOT have additional properties. Found extra property 'x'"];

Expand All @@ -51,7 +55,7 @@ describe('Invalid live pixel', () => {
describe('Valid live pixel', () => {
it('should exit normally', (done) => {
exec(
'npm run validate-ddg-live-pixel tests/test_data/valid test_pixels.json m.netp.tunnel.stop.failure /t/m_netp_tunnel_stop_failure_d_ios_phone?ud5=1',
`npm run validate-ddg-live-pixel ${validDefsPath} pixel_subfolder/test_pixels.json m.netp.tunnel.stop.failure /t/m_netp_tunnel_stop_failure_d_ios_phone?ud5=1`,
(error, _, stderr) => {
expect(stderr.length).to.equal(0);
expect(error).to.equal(null);
Expand Down
Loading