From bd05b362049d3adc559d4af0c8a223eb1998db78 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 8 Jan 2025 16:52:30 -0800 Subject: [PATCH] ci: simplify validation --- .../vaults-and-reserve-metrics-testing.yml | 29 +-------- scripts/validateData.mjs | 61 +++++++++++-------- 2 files changed, 35 insertions(+), 55 deletions(-) diff --git a/.github/workflows/vaults-and-reserve-metrics-testing.yml b/.github/workflows/vaults-and-reserve-metrics-testing.yml index 7df7b11d..7b043bfa 100644 --- a/.github/workflows/vaults-and-reserve-metrics-testing.yml +++ b/.github/workflows/vaults-and-reserve-metrics-testing.yml @@ -51,35 +51,8 @@ jobs: - name: Wait for GraphQL server run: sleep 60 - - name: Test VaultManagerGovernance + - name: Validate query responses run: ./scripts/validateData.mjs - env: - entity: vaultManagerGovernances - - - name: Test VaultManagerMetrics - run: ./scripts/validateData.mjs - env: - entity: vaultManagerMetrics - - - name: Test VaultManagerMetricsDaily - run: ./scripts/validateData.mjs - env: - entity: vaultManagerMetricsDailies - - - name: Test ReserveMetrics - run: ./scripts/validateData.mjs - env: - entity: reserveMetrics - - - name: Test ReserveAllocationMetrics - run: ./scripts/validateData.mjs - env: - entity: reserveAllocationMetrics - - - name: Test ReserveAllocationMetricsDaily - run: ./scripts/validateData.mjs - env: - entity: reserveAllocationMetricsDailies - name: Notify About Failure if: > diff --git a/scripts/validateData.mjs b/scripts/validateData.mjs index 39a69e80..d9986775 100755 --- a/scripts/validateData.mjs +++ b/scripts/validateData.mjs @@ -1,40 +1,47 @@ #! /usr/bin/env node /* eslint-env node */ import './lockdown.mjs'; + import { equal } from 'node:assert/strict'; -import { getQuery, expectations } from './queries.mjs'; -import { assertAllDefined } from '@agoric/internal'; +import { expectations, getQuery } from './queries.mjs'; const apiUrl = 'http://localhost:3000/'; console.log(`API URL set to: ${apiUrl}`); -const { entity } = process.env; -console.log(`Entity: ${entity}`); - -assertAllDefined({ entity }); - -try { - const graphqlQuery = { query: getQuery(entity) }; +/** + * @param {string} entity + */ +const checkEntity = async (entity) => { + try { + const graphqlQuery = { query: getQuery(entity) }; - const response = await fetch(apiUrl, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - }, - body: JSON.stringify(graphqlQuery), - }); + const response = await fetch(apiUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + }, + body: JSON.stringify(graphqlQuery), + }); - const jsonResponse = await response.json(); - console.log('Response:', JSON.stringify(jsonResponse)); - const nodes = jsonResponse?.data[entity]?.nodes; - console.log('Node:', nodes); + const jsonResponse = await response.json(); + console.log('Response:', JSON.stringify(jsonResponse)); + const nodes = jsonResponse?.data[entity]?.nodes; + console.log('Node:', nodes); - for (const key of Object.keys(expectations[entity])) { - console.log(`Checking ${entity} ${key}...`); - equal(nodes[0]?.[key], expectations[entity][key]), `Expected ${key} to be ${expectations[entity][key]}`; + for (const key of Object.keys(expectations[entity])) { + equal(nodes[0]?.[key], expectations[entity][key]), `Expected ${key} to be ${expectations[entity][key]}`; + } + } catch (error) { + console.error('Error:', error); + process.exit(1); } -} catch (error) { - console.error('Error:', error); - process.exit(1); +}; + +for (const entity of Object.keys(expectations)) { + console.log(`Validating ${entity}...`); + await checkEntity(entity); + console.log(`Validation successful for ${entity}.`); } + +console.log('Validation successful for all entities.');