Skip to content

Commit 95f28b2

Browse files
committed
feat: add shared mocks library
1 parent f0921ae commit 95f28b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1329
-4
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,18 @@ The Sia web libraries provide developers with convenient TypeScript SDKs for usi
4545

4646
## Internal
4747

48+
### Apps
49+
4850
- [website](apps/website) - The main [sia.tech](https://sia.tech) website with information on the Sia project and the Sia Foundation.
4951
- [assets](apps/assets) - Powers [api.sia.tech](https://api.sia.tech) and all downloadable assets on [sia.tech](https://sia.tech) such as the Sia software releases.
5052
- [crons](apps/crons) - Background tasks for [api.sia.tech](https://api.sia.tech) and [sia.tech](https://sia.tech).
5153

54+
### Testing
55+
56+
- [walletd-e2e](walletd-e2e) - App for testing walletd.
57+
- [@siafoundation/mock-walletd](mock-walletd) - `walletd` data and API mock library for testing.
58+
- [@siafoundation/mock-sia-central](mock-sia-central) - Sia Central data and API mock library for testing.
59+
5260
## Development
5361

5462
1. The Sia Web codebase is managed with the [Nx](https://nx.dev) build system. Either install `nx` globally via `npm install -g nx` or use `npx` to invoke commands.

libs/mock-sia-central/.babelrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
[
4+
"@nx/react/babel",
5+
{
6+
"runtime": "automatic",
7+
"useBuiltIns": "usage"
8+
}
9+
]
10+
],
11+
"plugins": []
12+
}

libs/mock-sia-central/.eslintrc.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"rules": {
5+
"@nx/dependency-checks": [
6+
"error",
7+
{
8+
"ignoredFiles": ["libs/mock-sia-central/rollup.config.js"]
9+
}
10+
]
11+
},
12+
"overrides": [
13+
{
14+
"files": ["*.json"],
15+
"parser": "jsonc-eslint-parser",
16+
"rules": {
17+
"@nx/dependency-checks": "error"
18+
}
19+
}
20+
]
21+
}

libs/mock-sia-central/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# mock-sia-central
2+
3+
Sia Central data and API mock library for testing.

libs/mock-sia-central/jest.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'mock-sia-central',
4+
preset: '../../jest.preset.js',
5+
transform: {
6+
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
7+
'^.+\\.[tj]sx?$': [
8+
'babel-jest',
9+
{
10+
presets: ['@nx/next/babel'],
11+
plugins: ['@babel/plugin-transform-private-methods'],
12+
},
13+
],
14+
},
15+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
16+
coverageDirectory: '../../coverage/libs/mock-sia-central',
17+
}

libs/mock-sia-central/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@siafoundation/mock-sia-central",
3+
"description": "Sia Central data and API mock library for testing.",
4+
"version": "0.0.0",
5+
"license": "MIT",
6+
"dependencies": {
7+
"@siafoundation/sia-central": "0.3.3",
8+
"playwright": "^1.42.1"
9+
},
10+
"types": "./src/index.d.ts"
11+
}

libs/mock-sia-central/project.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "mock-sia-central",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/mock-sia-central/src",
5+
"projectType": "library",
6+
"tags": [],
7+
"targets": {
8+
"build": {
9+
"executor": "@nx/rollup:rollup",
10+
"outputs": ["{options.outputPath}"],
11+
"options": {
12+
"outputPath": "dist/libs/mock-sia-central",
13+
"tsConfig": "libs/mock-sia-central/tsconfig.lib.json",
14+
"project": "libs/mock-sia-central/package.json",
15+
"entryFile": "libs/mock-sia-central/src/index.ts",
16+
"external": ["react/jsx-runtime"],
17+
"compiler": "tsc",
18+
"outputFileName": "index.js",
19+
"rollupConfig": "libs/mock-sia-central/rollup.config.js",
20+
"assets": [
21+
{
22+
"glob": "libs/mock-sia-central/*.md",
23+
"input": ".",
24+
"output": "."
25+
}
26+
]
27+
},
28+
"configurations": {}
29+
},
30+
"lint": {
31+
"executor": "@nx/eslint:lint",
32+
"outputs": ["{options.outputFile}"]
33+
},
34+
"test": {
35+
"executor": "@nx/jest:jest",
36+
"outputs": ["{workspaceRoot}/coverage/libs/mock-sia-central"],
37+
"options": {
38+
"jestConfig": "libs/mock-sia-central/jest.config.ts"
39+
}
40+
}
41+
}
42+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2+
const preserveDirectives = require('rollup-plugin-preserve-directives')
3+
4+
// https://github.com/rollup/rollup/issues/4699#issuecomment-1465302665
5+
function getRollupOptions(options) {
6+
return {
7+
...options,
8+
output: {
9+
...options.output,
10+
preserveModules: true,
11+
format: 'esm',
12+
sourcemap: true,
13+
},
14+
plugins: options.plugins.concat(preserveDirectives.default()),
15+
}
16+
}
17+
18+
module.exports = getRollupOptions

libs/mock-sia-central/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './siaCentralExchangeRates'
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { SiaCentralExchangeRatesResponse } from '@siafoundation/sia-central'
2+
import { Page } from 'playwright'
3+
4+
export function getMockSiaCentralExchangeRatesResponse(): SiaCentralExchangeRatesResponse {
5+
return {
6+
message: 'successfully retrieved exchange rate',
7+
type: 'success',
8+
rates: {
9+
sc: {
10+
aud: '0.016136871549',
11+
bch: '0.000021499880703',
12+
btc: '0.000000149047',
13+
cad: '0.014328484298',
14+
cny: '0.076310722577',
15+
eth: '0.0000029068532077',
16+
eur: '0.009737538604',
17+
gbp: '0.008359151948',
18+
jpy: '1.600530478116',
19+
ltc: '0.000116295710314',
20+
rub: '0.978819669836',
21+
scp: '0.0623627615062762',
22+
sf: '0.000000745235',
23+
usd: '0.010571307522',
24+
},
25+
},
26+
timestamp: '2024-03-26T13:12:22.7348119Z',
27+
}
28+
}
29+
30+
export async function mockApiSiaCentralExchangeRates({ page }: { page: Page }) {
31+
const json = getMockSiaCentralExchangeRatesResponse()
32+
await page.route(
33+
'https://api.siacentral.com/v2/market/exchange-rate?currencies=sc',
34+
async (route) => {
35+
await route.fulfill({ json })
36+
}
37+
)
38+
return json
39+
}

libs/mock-sia-central/tsconfig.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"jsx": "react-jsx",
5+
"allowJs": true,
6+
"esModuleInterop": true,
7+
"allowSyntheticDefaultImports": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"strict": true,
10+
"noImplicitOverride": true,
11+
"noPropertyAccessFromIndexSignature": true,
12+
"noImplicitReturns": true,
13+
"noFallthroughCasesInSwitch": true
14+
},
15+
"files": [],
16+
"include": [],
17+
"references": [
18+
{
19+
"path": "./tsconfig.lib.json"
20+
},
21+
{
22+
"path": "./tsconfig.spec.json"
23+
}
24+
]
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"types": [
6+
"node",
7+
"@nx/react/typings/cssmodule.d.ts",
8+
"@nx/react/typings/image.d.ts"
9+
]
10+
},
11+
"exclude": [
12+
"**/*.spec.ts",
13+
"**/*.test.ts",
14+
"**/*.spec.tsx",
15+
"**/*.test.tsx",
16+
"**/*.spec.js",
17+
"**/*.test.js",
18+
"**/*.spec.jsx",
19+
"**/*.test.jsx"
20+
],
21+
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"module": "commonjs",
6+
"types": ["jest", "node"]
7+
},
8+
"include": [
9+
"src/**/*.test.ts",
10+
"src/**/*.spec.ts",
11+
"src/**/*.test.tsx",
12+
"src/**/*.spec.tsx",
13+
"src/**/*.test.js",
14+
"src/**/*.spec.js",
15+
"src/**/*.test.jsx",
16+
"src/**/*.spec.jsx",
17+
"src/**/*.d.ts"
18+
]
19+
}

libs/mock-walletd/.babelrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
[
4+
"@nx/react/babel",
5+
{
6+
"runtime": "automatic",
7+
"useBuiltIns": "usage"
8+
}
9+
]
10+
],
11+
"plugins": []
12+
}

libs/mock-walletd/.eslintrc.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"rules": {
5+
"@nx/dependency-checks": [
6+
"error",
7+
{
8+
"ignoredFiles": ["libs/mock-walletd/rollup.config.js"]
9+
}
10+
]
11+
},
12+
"overrides": [
13+
{
14+
"files": ["*.json"],
15+
"parser": "jsonc-eslint-parser",
16+
"rules": {
17+
"@nx/dependency-checks": "error"
18+
}
19+
}
20+
]
21+
}

libs/mock-walletd/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# mock-walletd
2+
3+
`walletd` data and API mock library for testing.

libs/mock-walletd/jest.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'mock-walletd',
4+
preset: '../../jest.preset.js',
5+
transform: {
6+
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
7+
'^.+\\.[tj]sx?$': [
8+
'babel-jest',
9+
{
10+
presets: ['@nx/next/babel'],
11+
plugins: ['@babel/plugin-transform-private-methods'],
12+
},
13+
],
14+
},
15+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
16+
coverageDirectory: '../../coverage/libs/mock-walletd',
17+
}

libs/mock-walletd/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@siafoundation/mock-walletd",
3+
"description": "walletd data and API mock library for testing.",
4+
"version": "0.0.0",
5+
"license": "MIT",
6+
"dependencies": {
7+
"@siafoundation/types": "0.1.3",
8+
"@siafoundation/react-walletd": "3.0.0",
9+
"@siafoundation/units": "3.0.0",
10+
"playwright": "^1.42.1",
11+
"@siafoundation/mock-sia-central": "0.0.0"
12+
},
13+
"types": "./src/index.d.ts"
14+
}

libs/mock-walletd/project.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "mock-walletd",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/mock-walletd/src",
5+
"projectType": "library",
6+
"tags": [],
7+
"targets": {
8+
"build": {
9+
"executor": "@nx/rollup:rollup",
10+
"outputs": ["{options.outputPath}"],
11+
"options": {
12+
"outputPath": "dist/libs/mock-walletd",
13+
"tsConfig": "libs/mock-walletd/tsconfig.lib.json",
14+
"project": "libs/mock-walletd/package.json",
15+
"entryFile": "libs/mock-walletd/src/index.ts",
16+
"external": ["react/jsx-runtime"],
17+
"compiler": "tsc",
18+
"outputFileName": "index.js",
19+
"rollupConfig": "libs/mock-walletd/rollup.config.js",
20+
"assets": [
21+
{
22+
"glob": "libs/mock-walletd/*.md",
23+
"input": ".",
24+
"output": "."
25+
}
26+
]
27+
},
28+
"configurations": {}
29+
},
30+
"lint": {
31+
"executor": "@nx/eslint:lint",
32+
"outputs": ["{options.outputFile}"]
33+
},
34+
"test": {
35+
"executor": "@nx/jest:jest",
36+
"outputs": ["{workspaceRoot}/coverage/libs/mock-walletd"],
37+
"options": {
38+
"jestConfig": "libs/mock-walletd/jest.config.ts"
39+
}
40+
}
41+
}
42+
}

libs/mock-walletd/rollup.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2+
const preserveDirectives = require('rollup-plugin-preserve-directives')
3+
4+
// https://github.com/rollup/rollup/issues/4699#issuecomment-1465302665
5+
function getRollupOptions(options) {
6+
return {
7+
...options,
8+
output: {
9+
...options.output,
10+
preserveModules: true,
11+
format: 'esm',
12+
sourcemap: true,
13+
},
14+
plugins: options.plugins.concat(preserveDirectives.default()),
15+
}
16+
}
17+
18+
module.exports = getRollupOptions

0 commit comments

Comments
 (0)