Setting up tests for name and address endpoints

This commit is contained in:
Jamie Hewitt 2022-08-25 16:57:26 +03:00
parent d226949460
commit 4a61b881fc
4 changed files with 3627 additions and 279 deletions

3845
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,21 +9,28 @@
"clean": "rm -rf ./dist",
"format": "prettier --ignore-path .gitignore './**/*.{css,yml,js,ts,tsx,json}' --write",
"test:format": "npm run format && npm run lint",
"test": "ts-mocha -p test/tsconfig.json --exit test/**/*.test.ts",
"type-check": "tsc --noEmit"
},
"dependencies": {
"ethers": "^5.7.0"
},
"devDependencies": {
"@types/mocha": "^9.1.1",
"@typescript-eslint/eslint-plugin": "^5.28.0",
"@typescript-eslint/parser": "^5.29.0",
"@vercel/node": "^2.5.8",
"axios": "^0.27.2",
"chai": "^4.3.6",
"eslint": "^8.18.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.0",
"prettier": "^2.7.1",
"pretty-quick": "^3.1.3",
"typescript": "4.7.3"
"test-listen": "^1.1.0",
"ts-mocha": "^10.0.0",
"typescript": "4.7.3",
"vercel-node-server": "^2.2.1"
}
}

43
test/api.test.ts Normal file
View File

@ -0,0 +1,43 @@
import addressApi from '../api/address'
import nameApi from '../api/name'
import { createServer } from 'vercel-node-server'
import listen from 'test-listen'
// import express from 'express'
// import request from 'supertest'
import axios from 'axios'
// import type { VercelRequest, VercelResponse } from '@vercel/node'
import { assert } from 'chai'
let server
let url: string
const name = 'jellymcjellyfish.eth'
const accountId = '0x99840Df5Cb42faBE0Feb8811Aaa4BC99cA6C84e0'
describe('Testing ENS proxy API endpoints', function () {
this.timeout(10000)
it('Requesting address should return the expected response', async () => {
server = createServer(addressApi)
url = await listen(server)
const response = await axios.get(url, {
params: {
name
}
})
assert(response.data.address === accountId)
})
it('Requesting ENS name should return the expected response', async () => {
server = createServer(nameApi)
url = await listen(server)
const response = await axios.get(url, {
params: {
accountId
}
})
assert(response.data.name === name)
})
})
after(() => {
server.close()
})

9
test/tsconfig.json Normal file
View File

@ -0,0 +1,9 @@
{
"compilerOptions": {
"resolveJsonModule": true,
"lib": ["es6", "es7"],
"noUnusedLocals": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
}