Skip to content

Commit

Permalink
Merge pull request #32 from ryma2fhir/ryma2fhir-patch-5
Browse files Browse the repository at this point in the history
Update validate.test.ts
  • Loading branch information
ryma2fhir authored Jan 19, 2024
2 parents 77a9cbd + 7bcbbb1 commit e8b131f
Showing 1 changed file with 46 additions and 34 deletions.
80 changes: 46 additions & 34 deletions src/validate.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
getFhirClientJSON, isIgnoreFile, isIgnoreFolder, NEW_LINE, testFile
} from "./common.js";
import * as fs from "fs";
import * as fs from 'fs/promises';
import {describe, expect, jest} from "@jest/globals";
import axios, {AxiosInstance} from "axios";
import * as console from "console";
Expand All @@ -18,40 +18,52 @@ const args = require('minimist')(process.argv.slice(2))
let source = '../'
let examples: string

function readStrictValidation() {
try {
// Read the content of the JSON file
const data = fs.readFileSync('./options.json', 'utf8');

// Parse the JSON content
const options = JSON.parse(data);

// Access the attribute value or default to true if not found
const strictValidation = options['strict-validation'] === undefined ? true : JSON.parse(options['strict-validation']);

// Print the value
console.log('Strict Validation:', strictValidation);

// Return the attribute value
return strictValidation;
} catch (error) {
if (error.code === 'ENOENT') {
// File not found
console.error('Error: File not found, defaulting to true');
} else if (error instanceof SyntaxError) {
// JSON parsing error (attribute not found)
console.error('Error: Attribute not found in the JSON file, defaulting to true');
} else {
// Other errors
console.error('Error:', error);
}
function readStrictValidation(): Promise<boolean> {
return fs.readFile('options.json', 'utf8')
.then(data => {
const options: Record<string, string> = JSON.parse(data);

// Return true as the default value
return true;
}
}

const failOnWarning = readStrictValidation();
// Access the attribute value or default to true if not found
const strictValidation: boolean = options['strict-validation'] === undefined
? true
: options['strict-validation'].toLowerCase() === 'true';

// Validate that strictValidation is either true or false
if (strictValidation !== true && strictValidation !== false) {
console.error('Error: Invalid value for strict-validation. Defaulting to true.');
return true;
}

// Print the value
console.log('Strict Validation:', strictValidation);

// Return the attribute value
return strictValidation;
})
.catch(error => {
if (error.code === 'ENOENT') {
// File not found
console.error('Error: File not found, defaulting to true');
} else if (error instanceof SyntaxError) {
// JSON parsing error (attribute not found)
console.error('Error: Attribute not found in the JSON file, defaulting to true');
} else {
// Other errors
console.error('Error:', error);
}

// Return true as the default value
return true;
});
}

// Assign the result to the variable failOnWarningPromise
const failOnWarningPromise: Promise<boolean> = readStrictValidation();

// Use the variable failOnWarningPromise as needed
failOnWarningPromise.then(result => {
console.log('Fail on Warning:', result);
});

gitHubSummary += 'Strict validation: ' + failOnWarning + NEW_LINE;

Expand Down

0 comments on commit e8b131f

Please sign in to comment.