Skip to content

Commit

Permalink
fixes after rebase, fix port collision in test suite, add attestation…
Browse files Browse the repository at this point in the history
… route tests to v2 endpoint
  • Loading branch information
m0ar committed Jun 26, 2024
1 parent 6f251be commit 6a134c1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"build": "tsc",
"watch": "tsc --watch",
"start": "node dist/index.js",
"test": "PINO_LOG_LEVEL=silent PORT=5600 DPID_ENV=production vitest --run --no-file-parallelism",
"test": "PINO_LOG_LEVEL=silent PORT=5600 vitest --config vitest.config.ts",
"dev": "tsx --watch --inspect --inspect-port=9309 src/index.ts",
"prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write",
"lint": "eslint . --ext .ts --fix",
Expand Down
4 changes: 2 additions & 2 deletions src/dpid-reader/DpidReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ export class DpidReader {
let cleanVersion: string | undefined = !version
? undefined
: version?.substring(0, 1) == "v"
? version
: `v${parseInt(version || "0") + 1}`;
? version
: `v${parseInt(version || "0") + 1}`;

if (cleanVersion === "vNaN") {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ if (process.env.FALLBACK_RESOLVER) {
app.get("/*", legacyResolve);
} else {
app.get("/*", resolveGenericHandler);
};
}

app.listen(port, () => {
logger.info(`⚡️[server]: Server is running at http://localhost:${port}`);
Expand Down
25 changes: 14 additions & 11 deletions test/basics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { describe, it } from "vitest";
import request from "supertest";
import assert from "assert";
import { app } from "../src/index.js";
import { getNodesUrl } from "../src/util/config.js";

const NODES_URL = getNodesUrl();

describe("dPID resolution", { timeout: 3_000 }, function () {
describe("web resolution (for humans)", () => {
Expand All @@ -12,7 +15,7 @@ describe("dPID resolution", { timeout: 3_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46";
const expected = `${NODES_URL}/dpid/46`;
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand All @@ -29,7 +32,7 @@ describe("dPID resolution", { timeout: 3_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/v1";
const expected = `${NODES_URL}/dpid/46/v1`;

assert.equal(value, expected, "incorrect resolution");
})
Expand All @@ -47,7 +50,7 @@ describe("dPID resolution", { timeout: 3_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/v4";
const expected = `${NODES_URL}/dpid/46/v4`;
assert.equal(value, expected, "incorrect resolution");
});
});
Expand All @@ -59,7 +62,7 @@ describe("dPID resolution", { timeout: 3_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/v1";
const expected = `${NODES_URL}/dpid/46/v1`;
assert.equal(value, expected, "incorrect resolution");
});
});
Expand All @@ -71,7 +74,7 @@ describe("dPID resolution", { timeout: 3_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/v3";
const expected = `${NODES_URL}/dpid/46/v3`;
assert.equal(value, expected, "incorrect resolution");
});
});
Expand All @@ -83,7 +86,7 @@ describe("dPID resolution", { timeout: 3_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/attestations";
const expected = `${NODES_URL}/dpid/46/attestations`;
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand All @@ -100,7 +103,7 @@ describe("dPID resolution", { timeout: 3_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/v2/attestations";
const expected = `${NODES_URL}/dpid/46/v2/attestations`;
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand All @@ -117,7 +120,7 @@ describe("dPID resolution", { timeout: 3_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/v3/attestations";
const expected = `${NODES_URL}/dpid/46/v3/attestations`;
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand All @@ -134,7 +137,7 @@ describe("dPID resolution", { timeout: 3_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/attestations/scientific-manuscript";
const expected = `${NODES_URL}/dpid/46/attestations/scientific-manuscript`;
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand All @@ -151,7 +154,7 @@ describe("dPID resolution", { timeout: 3_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/v2/attestations/scientific-manuscript";
const expected = `${NODES_URL}/dpid/46/v2/attestations/scientific-manuscript`;
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand All @@ -168,7 +171,7 @@ describe("dPID resolution", { timeout: 3_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/v3/attestations/scientific-manuscript";
const expected = `${NODES_URL}/dpid/46/v3/attestations/scientific-manuscript`;
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand Down
13 changes: 6 additions & 7 deletions test/v2/resolvers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { getNodesUrl } from "../../src/util/config.js";
const BASE = "/api/v2/resolve";
// Set dynamically so tests can run against different environments
const NODES_URL = getNodesUrl();

describe("dPID", { timeout: 10_000 }, function () {
describe("web resolution (for humans)", () => {
it("should handle a plain dpid", async () => {
Expand Down Expand Up @@ -111,7 +110,7 @@ describe("dPID", { timeout: 10_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/attestations";
const expected = `${NODES_URL}/dpid/46/attestations`;
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand All @@ -128,7 +127,7 @@ describe("dPID", { timeout: 10_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/v2/attestations";
const expected = `${NODES_URL}/dpid/46/v2/attestations`;
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand All @@ -145,7 +144,7 @@ describe("dPID", { timeout: 10_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/v3/attestations";
const expected = `${NODES_URL}/dpid/46/v3/attestations`;
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand All @@ -162,7 +161,7 @@ describe("dPID", { timeout: 10_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/attestations/scientific-manuscript";
const expected = `${NODES_URL}/dpid/46/attestations/scientific-manuscript`;
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand All @@ -179,7 +178,7 @@ describe("dPID", { timeout: 10_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/v2/attestations/scientific-manuscript";
const expected = `${NODES_URL}/dpid/46/v2/attestations/scientific-manuscript`;
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand All @@ -196,7 +195,7 @@ describe("dPID", { timeout: 10_000 }, function () {
.then((res) => {
const value = res.header["location"];

const expected = "https://nodes.desci.com/dpid/46/v3/attestations/scientific-manuscript";
const expected = `${NODES_URL}/dpid/46/v3/attestations/scientific-manuscript`;
assert.equal(value, expected, "incorrect resolution");
})
.catch((err) => {
Expand Down
11 changes: 11 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
include: [ "test/**/*" ],
watch: false,
// the test files invoke the app on the same port
fileParallelism: false,
},

});

0 comments on commit 6a134c1

Please sign in to comment.