Add e2e tests

pull/2163/head
Jérémy Rialland 2022-06-02 15:28:08 +02:00 committed by Johan Girod
parent eea607828a
commit ed1b999fb8
9 changed files with 51200 additions and 22 deletions

View File

@ -1,13 +1,18 @@
{
"name": "api",
"license": "MIT",
"version": "0.0.0",
"description": "API du site mon-entreprise",
"repository": {
"type": "git",
"url": "https://github.com/betagouv/mon-entreprise.git",
"directory": "api"
},
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"test": "run validate",
"test": "run validate && vitest",
"test:type": "tsc --noEmit",
"validate": "yarn swagger-cli validate ./source/openapi.yaml",
"postinstall": "yarn build:openapi",
@ -20,12 +25,7 @@
"wait:openapi": "wait-on ./source/openapi.json",
"build:openapi": "yarn run swagger-cli bundle ./source/openapi.yaml -o ./source/openapi.json",
"build:openapi:watch": "nodemon -d 500ms -w ./source/openapi.yaml -x \"yarn build:openapi\"",
"clean": "rm -rf dist ./source/openapi.json"
},
"repository": {
"type": "git",
"url": "https://github.com/betagouv/mon-entreprise.git",
"directory": "api"
"clean": "rimraf dist ./source/openapi.json"
},
"dependencies": {
"@koa/cors": "^3.3.0",
@ -46,9 +46,12 @@
"@types/koa__router": "^8.0.11",
"@types/node": "^17.0.35",
"@types/swagger-ui-dist": "^3.30.1",
"chai-http": "^4.3.0",
"nodemon": "^2.0.16",
"rimraf": "^3.0.2",
"ts-node": "^10.8.0",
"typescript": "^4.7.2",
"vitest": "^0.13.1",
"wait-on": "^6.0.1"
}
}

View File

@ -28,7 +28,9 @@ app.use((ctx) => {
const port = process.env.PORT || 3004
app.listen(port, function () {
const server = app.listen(port, function () {
// eslint-disable-next-line no-console
console.log('listening on port:', port)
})
export { server, app }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,124 @@
import chaiHttp from 'chai-http'
import { chai, describe, expect, it } from 'vitest'
import { server } from '../index.js'
chai.use(chaiHttp)
describe('e2e test mon-entreprise api', () => {
it('Test evaluate brut => net + super brut', async () => {
await expect(
chai
.request(server)
.post('/api/v1/evaluate')
.send({
situation: {
'contrat salarié . rémunération . brut de base': '3500 €',
},
expressions: [
'contrat salarié . rémunération . net',
'contrat salarié . prix du travail',
],
})
.then((res) => {
expect(res.status).toMatchInlineSnapshot('200')
return JSON.parse(res.text) as Record<string, unknown>
})
).resolves.toMatchSnapshot()
})
it('Test evaluate micro entreprise', async () => {
await expect(
chai
.request(server)
.post('/api/v1/evaluate')
.send({
situation: {
'entreprise . activité': "'libérale'",
'entreprise . activité . libérale réglementée': 'non',
'entreprise . date de création': '03/05/2019',
'entreprise . catégorie juridique': "'EI'",
'entreprise . catégorie juridique . EI . auto-entrepreneur': 'oui',
"dirigeant . auto-entrepreneur . chiffre d'affaires": '42000 €/an',
'dirigeant . auto-entrepreneur . impôt . versement libératoire':
'non',
'impôt . méthode de calcul': "'taux neutre'",
},
expressions: [
{
valeur:
'dirigeant . auto-entrepreneur . cotisations et contributions',
unité: '€/an',
},
'dirigeant . rémunération . impôt',
'dirigeant . auto-entrepreneur . net après impôt',
],
})
.then((res) => {
expect(res.status).toMatchInlineSnapshot('200')
return JSON.parse(res.text) as Record<string, unknown>
})
).resolves.toMatchSnapshot()
})
it('Test rules endpoint', async () => {
await expect(
chai
.request(server)
.get('/api/v1/rules')
.then((res) => {
expect(res.status).toMatchInlineSnapshot('200')
return JSON.parse(res.text) as Record<string, unknown>
})
).resolves.toMatchSnapshot()
})
it('Test openapi.json endpoint', async () => {
await expect(
chai
.request(server)
.get('/api/v1/openapi.json')
.then((res) => {
expect(res.status).toMatchInlineSnapshot('200')
return JSON.parse(res.text) as Record<string, unknown>
})
).resolves.toMatchSnapshot()
})
it('Test doc endpoint', async () => {
await expect(
chai
.request(server)
.get('/api/v1/doc/')
.then((res) => {
expect(res.status).toMatchInlineSnapshot('200')
return res.text
})
).resolves.toMatchInlineSnapshot(`
"<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang=\\"en\\">
<head>
<meta charset=\\"UTF-8\\">
<title>Swagger UI</title>
<link rel=\\"stylesheet\\" type=\\"text/css\\" href=\\"./swagger-ui.css\\" />
<link rel=\\"stylesheet\\" type=\\"text/css\\" href=\\"index.css\\" />
<link rel=\\"icon\\" type=\\"image/png\\" href=\\"./favicon-32x32.png\\" sizes=\\"32x32\\" />
<link rel=\\"icon\\" type=\\"image/png\\" href=\\"./favicon-16x16.png\\" sizes=\\"16x16\\" />
</head>
<body>
<div id=\\"swagger-ui\\"></div>
<script src=\\"./swagger-ui-bundle.js\\" charset=\\"UTF-8\\"> </script>
<script src=\\"./swagger-ui-standalone-preset.js\\" charset=\\"UTF-8\\"> </script>
<script src=\\"./swagger-initializer.js\\" charset=\\"UTF-8\\"> </script>
</body>
</html>
"
`)
})
})

View File

@ -36,5 +36,5 @@
"esm": true
},
"include": ["source"],
"exclude": ["**/node_modules", "**/dist", "**/*.test.*"]
"exclude": ["**/node_modules", "**/dist", "vitest.config.ts"]
}

7
api/vitest.config.ts Normal file
View File

@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config'
export default defineConfig({
esbuild: {
target: 'ES2020',
},
})

View File

@ -5,16 +5,13 @@
"type": "git",
"url": "https://github.com/betagouv/mon-entreprise.git"
},
"engines": {
"node": "^16"
},
"type": "module",
"workspaces": [
"modele-social",
"exoneration-covid",
"api",
"site"
],
"type": "module",
"scripts": {
"pre-commit": "yarn workspaces foreach -pi run pre-commit",
"scalingo-postbuild": "echo 'yarn workspaces focus api && yarn workspace api run build' ; yarn workspaces focus api && yarn workspace api run build",
@ -37,7 +34,6 @@
"resolutions": {
"@mui/styled-engine": "npm:@mui/styled-engine-sc@latest"
},
"packageManager": "yarn@3.2.0",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0",
@ -54,5 +50,9 @@
"husky": "^8.0.0",
"prettier": "^2.6.2",
"rimraf": "^3.0.2"
},
"packageManager": "yarn@3.2.0",
"engines": {
"node": "^16"
}
}

View File

@ -3,7 +3,7 @@ import { Article } from '@/design-system/card'
import { Trans, useTranslation } from 'react-i18next'
type IframeIntegrationCardProps = {
sitePaths: { integration: { iframe: string } }
sitePaths: { développeur: { iframe: string } }
iframePath: string
}
@ -23,7 +23,7 @@ export function IframeIntegrationCard({
}
ctaLabel={t('nextSteps.integration-iframe.cta', 'Voir la documentation')}
to={{
pathname: sitePaths.integration.iframe,
pathname: sitePaths.développeur.iframe,
search: `?module=${iframePath}`,
}}
>

143
yarn.lock
View File

@ -6068,7 +6068,7 @@ __metadata:
languageName: node
linkType: hard
"@types/chai@npm:^4.3.1":
"@types/chai@npm:4, @types/chai@npm:^4.3.1":
version: 4.3.1
resolution: "@types/chai@npm:4.3.1"
checksum: 2ee246b76c469cd620a7a1876a73bc597074361b67d547b4bd96a0c1adb43597ede2d8589ab626192e14349d83cbb646cc11e2c179eeeb43ff11596de94d82c4
@ -6091,6 +6091,13 @@ __metadata:
languageName: node
linkType: hard
"@types/cookiejar@npm:*":
version: 2.1.2
resolution: "@types/cookiejar@npm:2.1.2"
checksum: f6e1903454007f86edd6c3520cbb4d553e1d4e17eaf1f77f6f75e3270f48cc828d74397a113a36942f5fe52f9fa71067bcfa738f53ad468fcca0bc52cb1cbd28
languageName: node
linkType: hard
"@types/cookies@npm:*":
version: 0.7.7
resolution: "@types/cookies@npm:0.7.7"
@ -6740,6 +6747,16 @@ __metadata:
languageName: node
linkType: hard
"@types/superagent@npm:^3.8.3":
version: 3.8.7
resolution: "@types/superagent@npm:3.8.7"
dependencies:
"@types/cookiejar": "*"
"@types/node": "*"
checksum: 87ca335703f203c5f558977f4a7cd29fef792698007952631575518085f1604791b7a85ceb4f03b395a20ce82f4e8c87d78b1a142b3721f5043195329a4bfc00
languageName: node
linkType: hard
"@types/swagger-ui-dist@npm:^3.30.1":
version: 3.30.1
resolution: "@types/swagger-ui-dist@npm:3.30.1"
@ -7759,15 +7776,18 @@ __metadata:
"@types/koa__router": ^8.0.11
"@types/node": ^17.0.35
"@types/swagger-ui-dist": ^3.30.1
chai-http: ^4.3.0
koa: ^2.13.4
koa-body: ^5.0.0
koa-static: ^5.0.0
modele-social: ^0.6.1
nodemon: ^2.0.16
publicodes: ^1.0.0-beta.41
rimraf: ^3.0.2
swagger-ui-dist: ^4.11.1
ts-node: ^10.8.0
typescript: ^4.7.2
vitest: ^0.13.1
wait-on: ^6.0.1
languageName: unknown
linkType: soft
@ -9154,6 +9174,21 @@ __metadata:
languageName: node
linkType: hard
"chai-http@npm:^4.3.0":
version: 4.3.0
resolution: "chai-http@npm:4.3.0"
dependencies:
"@types/chai": 4
"@types/superagent": ^3.8.3
cookiejar: ^2.1.1
is-ip: ^2.0.0
methods: ^1.1.2
qs: ^6.5.1
superagent: ^3.7.0
checksum: 273275ca08518145898e1c10adc1a2c8bbf79bd03415c4213a88a67e2c90fac3d611a25812bcffb59fce80399a914dd01a2014515daa5bec84cbb75a23c837a5
languageName: node
linkType: hard
"chai@npm:^4.3.6":
version: 4.3.6
resolution: "chai@npm:4.3.6"
@ -9718,7 +9753,7 @@ __metadata:
languageName: node
linkType: hard
"component-emitter@npm:^1.2.1":
"component-emitter@npm:^1.2.0, component-emitter@npm:^1.2.1":
version: 1.3.0
resolution: "component-emitter@npm:1.3.0"
checksum: b3c46de38ffd35c57d1c02488355be9f218e582aec72d72d1b8bbec95a3ac1b38c96cd6e03ff015577e68f550fbb361a3bfdbd9bb248be9390b7b3745691be6b
@ -9854,6 +9889,13 @@ __metadata:
languageName: node
linkType: hard
"cookiejar@npm:^2.1.0, cookiejar@npm:^2.1.1":
version: 2.1.3
resolution: "cookiejar@npm:2.1.3"
checksum: 88259983ebc52ceb23cdacfa48762b6a518a57872eff1c7ed01d214fff5cf492e2660d7d5c04700a28f1787a76811df39e8639f8e17670b3cf94ecd86e161f07
languageName: node
linkType: hard
"cookies@npm:~0.8.0":
version: 0.8.0
resolution: "cookies@npm:0.8.0"
@ -12691,6 +12733,17 @@ __metadata:
languageName: node
linkType: hard
"form-data@npm:^2.3.1":
version: 2.5.1
resolution: "form-data@npm:2.5.1"
dependencies:
asynckit: ^0.4.0
combined-stream: ^1.0.6
mime-types: ^2.1.12
checksum: 5134ada56cc246b293a1ac7678dba6830000603a3979cf83ff7b2f21f2e3725202237cfb89e32bcb38a1d35727efbd3c3a22e65b42321e8ade8eec01ce755d08
languageName: node
linkType: hard
"form-data@npm:^3.0.0":
version: 3.0.1
resolution: "form-data@npm:3.0.1"
@ -12713,6 +12766,13 @@ __metadata:
languageName: node
linkType: hard
"formidable@npm:^1.2.0":
version: 1.2.6
resolution: "formidable@npm:1.2.6"
checksum: 2b68ed07ba88302b9c63f8eda94f19a460cef6017bfda48348f09f41d2a36660c9353137991618e0e4c3db115b41e4b8f6fa63bc973b7a7c91dec66acdd02a56
languageName: node
linkType: hard
"formidable@npm:^2.0.1":
version: 2.0.1
resolution: "formidable@npm:2.0.1"
@ -14147,6 +14207,13 @@ __metadata:
languageName: node
linkType: hard
"ip-regex@npm:^2.0.0":
version: 2.1.0
resolution: "ip-regex@npm:2.1.0"
checksum: 331d95052aa53ce245745ea0fc3a6a1e2e3c8d6da65fa8ea52bf73768c1b22a9ac50629d1d2b08c04e7b3ac4c21b536693c149ce2c2615ee4796030e5b3e3cba
languageName: node
linkType: hard
"ip@npm:^1.1.5":
version: 1.1.5
resolution: "ip@npm:1.1.5"
@ -14514,6 +14581,15 @@ __metadata:
languageName: node
linkType: hard
"is-ip@npm:^2.0.0":
version: 2.0.0
resolution: "is-ip@npm:2.0.0"
dependencies:
ip-regex: ^2.0.0
checksum: ad85d3a0bccca2c0096f5067b8f5fd0a0f9a26e5ed0990bb88eca004853422fbec4a26ec7a70342888f866074a9720b2cc11428e26c5950d6822a1dbefb80307
languageName: node
linkType: hard
"is-lambda@npm:^1.0.1":
version: 1.0.1
resolution: "is-lambda@npm:1.0.1"
@ -16125,7 +16201,7 @@ __metadata:
languageName: node
linkType: hard
"methods@npm:^1.1.2, methods@npm:~1.1.2":
"methods@npm:^1.1.1, methods@npm:^1.1.2, methods@npm:~1.1.2":
version: 1.1.2
resolution: "methods@npm:1.1.2"
checksum: 0917ff4041fa8e2f2fda5425a955fe16ca411591fbd123c0d722fcf02b73971ed6f764d85f0a6f547ce49ee0221ce2c19a5fa692157931cecb422984f1dcd13a
@ -16198,7 +16274,7 @@ __metadata:
languageName: node
linkType: hard
"mime@npm:1.6.0":
"mime@npm:1.6.0, mime@npm:^1.4.1":
version: 1.6.0
resolution: "mime@npm:1.6.0"
bin:
@ -18235,7 +18311,7 @@ __metadata:
languageName: node
linkType: hard
"qs@npm:^6.10.0, qs@npm:^6.4.0":
"qs@npm:^6.10.0, qs@npm:^6.4.0, qs@npm:^6.5.1":
version: 6.10.3
resolution: "qs@npm:6.10.3"
dependencies:
@ -20826,6 +20902,24 @@ __metadata:
languageName: node
linkType: hard
"superagent@npm:^3.7.0":
version: 3.8.3
resolution: "superagent@npm:3.8.3"
dependencies:
component-emitter: ^1.2.0
cookiejar: ^2.1.0
debug: ^3.1.0
extend: ^3.0.0
form-data: ^2.3.1
formidable: ^1.2.0
methods: ^1.1.1
mime: ^1.4.1
qs: ^6.5.1
readable-stream: ^2.3.5
checksum: b13d0303259d76c9180bd40d97d9f0713760f5ced1aef089bdb2fcdf69cfaef89004cd6e986416d59bd9a2f0f9933d72521b5171fa26f89b781a2c3460c516fe
languageName: node
linkType: hard
"supports-color@npm:^5.3.0, supports-color@npm:^5.5.0":
version: 5.5.0
resolution: "supports-color@npm:5.5.0"
@ -21173,6 +21267,13 @@ __metadata:
languageName: node
linkType: hard
"tinypool@npm:^0.1.3":
version: 0.1.3
resolution: "tinypool@npm:0.1.3"
checksum: 13ac687a23c03b02c2bf0b9711a3bb191d2c37941775a001b9617aac541c11ba144fb08de74f3f9723ec2649410f5d4fa7f0398fedd462b39fe3b30d19615ad8
languageName: node
linkType: hard
"tinyspy@npm:^0.3.2":
version: 0.3.2
resolution: "tinyspy@npm:0.3.2"
@ -22378,6 +22479,38 @@ __metadata:
languageName: node
linkType: hard
"vitest@npm:^0.13.1":
version: 0.13.1
resolution: "vitest@npm:0.13.1"
dependencies:
"@types/chai": ^4.3.1
"@types/chai-subset": ^1.3.3
chai: ^4.3.6
debug: ^4.3.4
local-pkg: ^0.4.1
tinypool: ^0.1.3
tinyspy: ^0.3.2
vite: ^2.9.9
peerDependencies:
"@vitest/ui": "*"
c8: "*"
happy-dom: "*"
jsdom: "*"
peerDependenciesMeta:
"@vitest/ui":
optional: true
c8:
optional: true
happy-dom:
optional: true
jsdom:
optional: true
bin:
vitest: vitest.mjs
checksum: 28006581e3c16f67838f1a7c2f08cd67415267849d5a2f46ece7fcceed683a1c2beb7c153d5e34e6891fd0f40d032ea0b3aa8775890f00c057fe0e91735114c7
languageName: node
linkType: hard
"vitest@npm:^0.9.4":
version: 0.9.4
resolution: "vitest@npm:0.9.4"