Skip to content

Commit

Permalink
chore(test): add e2e test for resolver routes
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Sep 13, 2024
1 parent 91aff62 commit 3e606a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
13 changes: 6 additions & 7 deletions src/routes/arns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as system from '../system.js';
import { dataHandler } from './data/index.js';
import { headerNames } from '../constants.js';
import { sendNotFound } from './data/handlers.js';
import { DEFAULT_ARNS_TTL_SECONDS } from '../resolution/trusted-gateway-arns-resolver.js';

export const arnsRouter = Router();

Expand Down Expand Up @@ -53,18 +54,16 @@ arnsRouter.get('/ar-io/resolver/:name', async (req, res) => {

const { resolvedId, ttl, processId, resolvedAt } = resolved;

// check if they are undefined
if (
resolvedId === undefined ||
ttl === undefined ||
processId === undefined
) {
if (resolvedId === undefined) {
sendNotFound(res);
return;
}

res.header(headerNames.arnsResolvedId, resolvedId);
res.header(headerNames.arnsTtlSeconds, ttl.toString());
res.header(
headerNames.arnsTtlSeconds,
ttl.toString() || DEFAULT_ARNS_TTL_SECONDS.toString(),
);
res.header(headerNames.arnsProcessId, processId);

// add arns headers
Expand Down
22 changes: 6 additions & 16 deletions test/end-to-end/arns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,8 @@ describe('ArNS', function () {

// verify the /ar-io/resolver/:name endpoint
it('Verifying that /ar-io/resolver/:name returns 200 and resolution data', async function () {
const txId = 'TB2wJyKrPnkAW79DAwlJYwpgdHKpijEJWQfcwX715Co';
const res = await axios.get(
'http://localhost:4000/ar-io/resolver/ardrive',
{
headers: { Host: 'ardrive.ar-io.localhost' },
},
);
const txId = '7czHwMqgYHC3eJrPagyFA03UT4YXIN1um__tpHUXAHE';
const res = await axios.get('http://localhost:4000/ar-io/resolver/ardrive');

assert.strictEqual(res.status, 200);
assert.strictEqual(res.data.txId, txId);
Expand All @@ -129,15 +124,10 @@ describe('ArNS', function () {

// verify the headers are set correctly on the response
it('Verifying that /ar-io/resolver/:name returns 200 and sets the correct headers', async function () {
const txId = 'TB2wJyKrPnkAW79DAwlJYwpgdHKpijEJWQfcwX715Co';
const res = await axios.get(
'http://localhost:4000/ar-io/resolver/ardrive',
{
headers: { Host: 'ardrive.ar-io.localhost' },
},
);
const txId = '7czHwMqgYHC3eJrPagyFA03UT4YXIN1um__tpHUXAHE';
const res = await axios.get('http://localhost:4000/ar-io/resolver/ardrive');

assert.strictEqual(typeof res.headers['x-arns-resolved-id'], txId);
assert.strictEqual(res.headers['x-arns-resolved-id'], txId);
assert.strictEqual(typeof res.headers['x-arns-ttl-seconds'], 'string');
assert.strictEqual(typeof res.headers['x-arns-process-id'], 'string');
});
Expand All @@ -146,7 +136,7 @@ describe('ArNS', function () {
const res = await axios.get(
'http://localhost:4000/ar-io/resolver/nonexistent',
{
headers: { Host: 'ardrive.ar-io.localhost' },
validateStatus: (status) => status === 404, // only accept 404 status
},
);

Expand Down

0 comments on commit 3e606a6

Please sign in to comment.