Merge pull request #566 from kolplattformen/feat/add-api-test-app

Feat: Add api test app
This commit is contained in:
Viktor Sarström 2021-11-30 22:34:22 +01:00 committed by GitHub
commit 765ad2d56a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 150 additions and 15 deletions

View File

@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}

View File

View File

View File

@ -0,0 +1 @@
declare module 'h2m'

View File

View File

@ -0,0 +1,3 @@
export const environment = {
production: false,
}

View File

@ -0,0 +1,3 @@
export const environment = {
production: true,
}

View File

@ -1,7 +1,3 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */
/**
* A more elaborated test file for local development
* - Support for proxy (i recommend Burp Suite https://portswigger.net/burp/communitydownload)
@ -13,18 +9,18 @@ const { inspect } = require('util')
const nodeFetch = require('node-fetch')
const { CookieJar } = require('tough-cookie')
const fetchCookie = require('fetch-cookie/node-fetch')
// eslint-disable-next-line import/no-unresolved
const { writeFile, readFile } = require('fs/promises')
const path = require('path')
const fs = require('fs')
const HttpProxyAgent = require('https-proxy-agent')
const agentWrapper = require('./agentFetchWrapper')
const init = require('./dist/api-skolplattformen/lib').default
const agentWrapper = require('./app/agentFetchWrapper')
const init = require('@skolplattformen/api-skolplattformen').default
const [, , personalNumber] = process.argv
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
const cookieJar = new CookieJar()
let bankIdUsed = false
const recordFolder = `${__dirname}/record`
async function run() {
const agent = new HttpProxyAgent('http://localhost:8080')
@ -40,16 +36,16 @@ async function run() {
if (bankIdUsed) {
const sessionCookie = getSessionCookieFromCookieJar()
ensureDirectoryExistence('./record')
ensureDirectoryExistence(recordFolder)
await writeFile(
'./record/latestSessionCookie.txt',
`${recordFolder}/latestSessionCookie.txt`,
JSON.stringify(sessionCookie)
)
console.log(
'Session cookie saved to file ./record/latesSessionCookie.txt'
`Session cookie saved to file ${recordFolder}/latesSessionCookie.txt`
)
}
console.log('user')
console.log('user') //-
const user = await api.getUser()
console.log(user)
@ -64,7 +60,7 @@ async function run() {
console.log('classmates')
const classmates = await api.getClassmates(children[0])
console.log(classmates)
*/
try {
console.log('schedule')
const schedule = await api.getSchedule(
@ -139,7 +135,7 @@ async function Login(api) {
try {
console.log('Attempt to use saved session cookie to login')
const rawContent = await readFile('./record/latestSessionCookie.txt')
const rawContent = await readFile(`${recordFolder}/latestSessionCookie.txt`)
const sessionCookie = JSON.parse(rawContent)
await api.setSessionCookie(`${sessionCookie.key}=${sessionCookie.value}`)
@ -155,7 +151,7 @@ async function Login(api) {
console.log('*** BankId login - open BankId app ***')
if (!personalNumber) {
console.error(
'You must pass in a valid personal number, eg `node run 197001011111`'
'You must pass in a valid personal number, eg `nx serve api-test-app --args=197001011111,`'
)
process.exit(1)
}
@ -189,7 +185,7 @@ function getSessionCookieFromCookieJar() {
const record = async (info, data) => {
const name = info.error ? `${info.name}_error` : info.name
const filename = `./record/${name}.json`
const filename = `${recordFolder}/${name}.json`
ensureDirectoryExistence(filename)
const content = {
url: info.url,

View File

@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["node"],
},
"exclude": ["**/*.spec.ts", "**/*.spec.js"],
"include": ["**/*.ts", "**/*.js"],
}

View File

@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
}
],
"compilerOptions": {
"allowJs": true,
"esModuleInterop": true,
},
}

View File

@ -1,5 +1,6 @@
import {
Api,
Fetch,
FetcherOptions,
RNCookieManager,
ToughCookieJar,

View File

@ -36,6 +36,9 @@
"api": {
"tags": []
},
"api-test-app": {
"tags": []
},
"curriculum": {
"tags": []
},

View File

@ -79,6 +79,7 @@
"@nrwl/eslint-plugin-nx": "^12.10.0",
"@nrwl/jest": "12.10.0",
"@nrwl/linter": "12.10.0",
"@nrwl/node": "12.10.0",
"@nrwl/react": "12.10.0",
"@nrwl/react-native": "^12.10.0",
"@nrwl/tao": "12.10.0",

View File

@ -49,6 +49,51 @@
}
}
},
"api-test-app": {
"root": "apps/api-test-app",
"sourceRoot": "apps/api-test-app/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/node:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/api-test-app",
"main": "apps/api-test-app/src/main.js",
"tsConfig": "apps/api-test-app/tsconfig.app.json",
"assets": ["apps/api-test-app/src/assets"]
},
"configurations": {
"production": {
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/api-test-app/src/environments/environment.js",
"with": "apps/api-test-app/src/environments/environment.prod.js"
}
]
}
}
},
"serve": {
"executor": "@nrwl/node:execute",
"options": {
"buildTarget": "api-test-app:build",
"watch": false,
"inspect": false
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/api-test-app/**/*.js"]
}
}
}
},
"api": {
"root": "libs/api",
"sourceRoot": "libs/api",

View File

@ -1823,6 +1823,33 @@
tmp "~0.2.1"
tslib "^2.0.0"
"@nrwl/node@12.10.0":
version "12.10.0"
resolved "https://registry.yarnpkg.com/@nrwl/node/-/node-12.10.0.tgz#1065dfb0bea758d7c1e2f89a00c97e191408be86"
integrity sha512-21bBgDOhmUs3o7oqjfb78weRevh7lk+5ZIWE4n6o+x/AYx4iXPn8mUQFnIfl7smRRVfuRh0GnqZg7BEy8fj+sg==
dependencies:
"@nrwl/devkit" "12.10.0"
"@nrwl/jest" "12.10.0"
"@nrwl/linter" "12.10.0"
"@nrwl/workspace" "12.10.0"
chalk "4.1.0"
circular-dependency-plugin "5.2.0"
copy-webpack-plugin "6.4.1"
fork-ts-checker-webpack-plugin "6.2.10"
fs-extra "^9.1.0"
glob "7.1.4"
license-webpack-plugin "2.3.15"
rxjs "^6.5.4"
rxjs-for-await "0.0.2"
source-map-support "0.5.19"
tree-kill "1.2.2"
ts-loader "5.4.5"
tsconfig-paths-webpack-plugin "3.4.1"
tslib "^2.0.0"
webpack "4.46.0"
webpack-merge "4.2.1"
webpack-node-externals "1.7.2"
"@nrwl/react-native@^12.10.0":
version "12.10.0"
resolved "https://registry.yarnpkg.com/@nrwl/react-native/-/react-native-12.10.0.tgz#bff464f7cd8db50b0f0dc002dd8dd07922b4150e"
@ -13316,6 +13343,14 @@ source-map-resolve@^0.6.0:
atob "^2.1.2"
decode-uri-component "^0.2.0"
source-map-support@0.5.19:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map-support@^0.5.16, source-map-support@^0.5.17, source-map-support@^0.5.6, source-map-support@~0.5.12, source-map-support@~0.5.20:
version "0.5.20"
resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.20.tgz"
@ -14125,6 +14160,11 @@ tr46@^2.1.0:
dependencies:
punycode "^2.1.1"
tree-kill@1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==
truncate-utf8-bytes@^1.0.0:
version "1.0.2"
resolved "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz"