Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
refactor(app): formatted files and fixed admin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilit0x committed Sep 12, 2024
1 parent b44ad9a commit 0cf6e2e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 88 deletions.
11 changes: 6 additions & 5 deletions assurance/admin_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,18 @@ Deno.test("initialize empty rssd", async (t) => {
});

Deno.test("merge RSSDs", async () => {
const mergeResult = await $`surveilr admin merge`;
const aggregatedRssdPath = path.join(
E2E_TEST_DIR,
"resource-surveillance-aggregated.sqlite.db",
);

const mergeResult = await $`surveilr admin merge -d ${aggregatedRssdPath}`;
assertEquals(
mergeResult.code,
0,
`❌ Error: Failed to merge RSSDs`,
);

const aggregatedRssdPath = path.join(
E2E_TEST_DIR,
"resource-surveillance-aggregated.sqlite.db",
);
assertExists(
await Deno.stat(aggregatedRssdPath).catch(() => null),
`❌ Error: RSSD: ${aggregatedRssdPath} was not created`,
Expand Down
144 changes: 66 additions & 78 deletions assurance/ingest_direct_messages_test.ts
Original file line number Diff line number Diff line change
@@ -1,100 +1,88 @@
import { assert, assertEquals, assertExists } from "jsr:@std/assert@1";
import { assertEquals, assertExists } from "jsr:@std/assert@1";
import * as path from "https://deno.land/[email protected]/path/mod.ts";
import { $ } from "https://deno.land/x/[email protected]/mod.ts";
import { DB } from "https://deno.land/x/[email protected]/mod.ts";

// # TODO: automatically upgrade surveilr
// adming merge command
// # TODO: commands
// # 1. add notebook orchestration: surveilr orchestrate notebooks --cell="%htmlAnchors%" -a "key1=value1" -a "name=starting"
// # 2. IMAP
// # 3. use the piping method to execute orchestration
// # 4. add multitenancy tests
// // await $`surveilr orchestrate -n "dd" -s https://raw.githubusercontent.com/opsfolio/resource-surveillance-commons/main/pattern/privacy/anonymize-sample/de-identification/deidentification.sql -s ${REPO_DIR}/pattern/privacy/anonymize-sample/de-identification/`;

const E2E_TEST_DIR = path.join(Deno.cwd(), "assurance");
const ZIP_URL =
"https://github.com/opsfolio/resource-surveillance-commons/raw/main/pattern/direct-messaging-service/ingest.zip";
"https://github.com/opsfolio/resource-surveillance-commons/raw/main/pattern/direct-messaging-service/ingest.zip";
const ZIP_FILE = path.join(E2E_TEST_DIR, "ingest.zip");
const INGEST_DIR = path.join(E2E_TEST_DIR, "ingest");
// const INGEST_DIR = "ingest";
const DEFAULT_RSSD_PATH = path.join(
E2E_TEST_DIR,
"resource-surveillance-direct-message.sqlite.db",
E2E_TEST_DIR,
"resource-surveillance-direct-message.e2e.sqlite.db",
);
const TEST_FIXTURES_DIR = path.join(E2E_TEST_DIR, "test-fixtures");

export async function countFilesInDirectory(
directoryPath: string,
directoryPath: string,
): Promise<number> {
let fileCount = 0;
let fileCount = 0;

for await (const dirEntry of Deno.readDir(directoryPath)) {
if (dirEntry.isFile) {
fileCount++;
}
for await (const dirEntry of Deno.readDir(directoryPath)) {
if (dirEntry.isFile) {
fileCount++;
}
}

return fileCount;
return fileCount;
}

Deno.test("file ingestion", async (t) => {
await t.step({
name: "download-zip",
fn: async () => {
if (!await Deno.stat(ZIP_FILE).catch(() => false)) {
await $`wget -P ${E2E_TEST_DIR} ${ZIP_URL}`;
}

assertExists(
await Deno.stat(ZIP_FILE).catch(() => null),
"❌ Error: Data file does not exist after download.",
);
await t.step({
name: "download-zip",
fn: async () => {
if (!await Deno.stat(ZIP_FILE).catch(() => false)) {
await $`wget -P ${E2E_TEST_DIR} ${ZIP_URL}`;
}

if (!await Deno.stat(INGEST_DIR).catch(() => false)) {
const unzipResult =
await $`unzip ${ZIP_FILE} -d ${E2E_TEST_DIR}`;
assertExists(
await Deno.stat(ZIP_FILE).catch(() => null),
"❌ Error: Data file does not exist after download.",
);

assertEquals(
unzipResult.code,
0,
"❌ Error: Failed to unzip the data file.",
);
}
if (!await Deno.stat(INGEST_DIR).catch(() => false)) {
const unzipResult = await $`unzip ${ZIP_FILE} -d ${E2E_TEST_DIR}`;

assertExists(
await Deno.stat(INGEST_DIR).catch(() => null),
`❌ Error: Ingest directory ${INGEST_DIR} does not exist after unzipping.`,
);
},
ignore: false,
});
await t.step("surveilr ingest files", async () => {
assertExists(
await Deno.stat(INGEST_DIR).catch(() => null),
`❌ Error: Ingest directory ${INGEST_DIR} before surveilr ingest`,
);

if (await Deno.stat(DEFAULT_RSSD_PATH).catch(() => null)) {
await Deno.remove(DEFAULT_RSSD_PATH).catch(() => false);
}
console.log(INGEST_DIR);
const ingestResult =
await $`surveilr ingest files -d ${DEFAULT_RSSD_PATH} -r ${INGEST_DIR}`;
assertEquals(
ingestResult.code,
0,
`❌ Error: Failed to ingest data in ${INGEST_DIR}`,
unzipResult.code,
0,
"❌ Error: Failed to unzip the data file.",
);
}

assertExists(
await Deno.stat(DEFAULT_RSSD_PATH).catch(() => null),
`❌ Error: ${DEFAULT_RSSD_PATH} does not exist`,
);
});
const db = new DB(DEFAULT_RSSD_PATH);
await t.step("inbox data", async () => {
db.execute(`
assertExists(
await Deno.stat(INGEST_DIR).catch(() => null),
`❌ Error: Ingest directory ${INGEST_DIR} does not exist after unzipping.`,
);
},
ignore: false,
});
await t.step("surveilr ingest files", async () => {
assertExists(
await Deno.stat(INGEST_DIR).catch(() => null),
`❌ Error: Ingest directory ${INGEST_DIR} before surveilr ingest`,
);

if (await Deno.stat(DEFAULT_RSSD_PATH).catch(() => null)) {
await Deno.remove(DEFAULT_RSSD_PATH).catch(() => false);
}
console.log(INGEST_DIR);
const ingestResult =
await $`surveilr ingest files -d ${DEFAULT_RSSD_PATH} -r ${INGEST_DIR}`;
assertEquals(
ingestResult.code,
0,
`❌ Error: Failed to ingest data in ${INGEST_DIR}`,
);

assertExists(
await Deno.stat(DEFAULT_RSSD_PATH).catch(() => null),
`❌ Error: ${DEFAULT_RSSD_PATH} does not exist`,
);
});
const db = new DB(DEFAULT_RSSD_PATH);
await t.step("inbox data", () => {
db.execute(`
DROP VIEW IF EXISTS mail_content_detail;
CREATE VIEW mail_content_detail AS
SELECT
Expand Down Expand Up @@ -132,10 +120,10 @@ Deno.test("file ingestion", async (t) => {
FROM
mail_content_detail mcd;`);
const result = db.query(
`SELECT COUNT(*) AS count FROM inbox`,
);
assertEquals(result.length, 1);
});
db.close();
const result = db.query(
`SELECT COUNT(*) AS count FROM inbox`,
);
assertEquals(result.length, 1);
});
db.close();
});
4 changes: 1 addition & 3 deletions assurance/ingest_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ Deno.test("multitenancy file ingestion", async (t) => {
db.close();
});


Deno.test("csv auto transformation", async (t) => {
const csvAutoTeansformationRssd = path.join(
E2E_TEST_DIR,
Expand Down Expand Up @@ -298,7 +297,6 @@ Deno.test("csv auto transformation", async (t) => {
);
assertEquals(result.length, 1);
const numberOfConvertedRecords = result[0][0];
console.log({ numberOfConvertedRecords })
initialnumberOfConvertedRecords = numberOfConvertedRecords;

const csvRows = await countCSVRows(`${TEST_FIXTURES_DIR}/allergies.csv`);
Expand All @@ -321,7 +319,7 @@ Deno.test("csv auto transformation", async (t) => {
);
assertEquals(result.length, 1);
const numberOfConvertedRecords = result[0][0];
console.log({ numberOfConvertedRecords })
console.log({ numberOfConvertedRecords });

assertEquals(numberOfConvertedRecords, initialnumberOfConvertedRecords);
});
Expand Down
2 changes: 0 additions & 2 deletions service/diabetes-research-hub/ux.sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,6 @@ SELECT
`;
}


@drhNav({
caption: "Participant Information",
abbreviatedCaption: "Participant Information",
Expand Down Expand Up @@ -800,7 +799,6 @@ SELECT
`;
}

}

export async function drhSQL() {
Expand Down

2 comments on commit 0cf6e2e

@deno-deploy
Copy link

@deno-deploy deno-deploy bot commented on 0cf6e2e Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

Your deployment uses decorators. The default for 'experimentalDecorators' will be changing to 'false'. In the meantime, please explicitly set the 'experimentalDecorators' compiler option. For more information, see https://deno.com/deploy/changelog#es-decorators-are-enabled-on-deno-deploy-replacing-experimental-ts-decorators

@deno-deploy
Copy link

@deno-deploy deno-deploy bot commented on 0cf6e2e Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

Your deployment uses decorators. The default for 'experimentalDecorators' will be changing to 'false'. In the meantime, please explicitly set the 'experimentalDecorators' compiler option. For more information, see https://deno.com/deploy/changelog#es-decorators-are-enabled-on-deno-deploy-replacing-experimental-ts-decorators

Please sign in to comment.