Skip to content

Commit

Permalink
Add 50% unit test coverage for utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Aishlia committed Mar 16, 2023
1 parent 1508c7c commit 545394e
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ backend
.idea
# Local Netlify folder
.netlify
node_modules
1 change: 1 addition & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ accumulate.env
node_modules
.env
yarn-error.log
coverage
6 changes: 6 additions & 0 deletions client/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
transform: { '^.+\\.ts?$': 'ts-jest' },
testEnvironment: 'node',
testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
}
6 changes: 5 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"local": "DEBUG=true webpack serve --mode=development",
"build": "webpack --mode=production --config webpack.config.js",
"prepare": "cd .. && husky install client/.husky",
"test": "jest"
"test": "jest",
"type": "module"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,html,css}": "npx prettier --check"
Expand Down Expand Up @@ -36,6 +37,7 @@
"@babel/preset-typescript": "^7.18.6",
"@babel/runtime": "^7.14.0",
"@svgr/webpack": "^6.2.1",
"@types/jest": "^29.4.3",
"@types/lodash.debounce": "^4.0.7",
"@types/react": "^18.0.27",
"assert": "^2.0.0",
Expand Down Expand Up @@ -63,6 +65,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-standard": "^5.0.0",
"file-loader": "^6.2.0",
"hest": "^1.0.5",
"html-webpack-change-assets-extension-plugin": "^1.3.1",
"html-webpack-plugin": "^5.3.1",
"https-browserify": "^1.0.0",
Expand All @@ -81,6 +84,7 @@
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"style-loader": "^2.0.0",
"ts-jest": "^29.0.5",
"typescript": "^4.9.4",
"webpack": "^5.73.0",
"webpack-bundle-analyzer": "^3.6.1",
Expand Down
46 changes: 46 additions & 0 deletions client/src/api/tests/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { nameUtils } from '../utils'
import { utils } from '../utils'
import { getDomainLevel } from '../utils'

describe('Testing nameUtils', () => {
test('isValidName', () => {
expect(nameUtils.isValidName('**foo:)')).toBe(false)
expect(nameUtils.isValidName('openconsensus.country')).toBe(false)
expect(nameUtils.isValidName('123456789')).toBe(true)
expect(nameUtils.isValidName('openconsensus')).toBe(true)
})
test('isTaken', () => {
expect(nameUtils.isTaken('0')).toBe(true)
expect(nameUtils.isTaken('openconsensus')).toBe(false)
})
})

describe('Testing utils', () => {
test('hexView', () => {
expect(utils.hexView(new Uint8Array(2))).toBe('0000')
})
test('hexString', () => {
expect(utils.hexString(new Uint8Array(2))).toBe('0x0000')
})
// test('keccak', () => {
// expect(utils.keccak(new Uint8Array(2))).toBe("foo")
// });
// test('stringToBytes', () => {
// expect(utils.stringToBytes("foo")).toBe([102, 111, 111])
// });
test('keccak256', () => {
expect(utils.keccak256('foo', false)).toBe(
'41b1a0649752af1b28b3dc29a1556eee781e4a4c3a1f7f53f90fa834de098c4d'
)
})
})

describe('Testing getDomainLevel', () => {
test('getDomainLevel', () => {
expect(getDomainLevel('1')).toBe('legendary')
expect(getDomainLevel('11111')).toBe('super_rare')
expect(getDomainLevel('11111111')).toBe('rare')
expect(getDomainLevel('1111111111')).toBe('common')
expect(getDomainLevel('11111111111111111111')).toBe('common')
})
})
Loading

0 comments on commit 545394e

Please sign in to comment.