Merge pull request #603 from kolplattformen/feature/fix-vklass-deps

fix: jest configuration for vklass and hjärntorget
This commit is contained in:
Viktor Sarström 2021-12-17 07:54:21 +01:00 committed by GitHub
commit c202ca2af5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 243 additions and 4701 deletions

View File

@ -1,9 +1,6 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
transform: {
'.(ts|tsx)': 'ts-jest',
},
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$',
moduleFileExtensions: ['ts', 'tsx', 'js'],
displayName: 'api-hjarntorget',
resolver: '@nrwl/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'html', 'tsx', 'jsx'],
setupFilesAfterEnv: ['<rootDir>/test-setup.ts'],
}

View File

@ -1,71 +1,94 @@
import { ApiHjarntorget } from './apiHjarntorget'
import { checkStatus } from './loginStatus'
import { wrapToughCookie } from '@skolplattformen/api'
import { CookieJar } from 'tough-cookie'
import { ApiHjarntorget } from './apiHjarntorget'
const setupSuccessfullLoginInitiation = (fetcherMock: jest.Mock) => {
// 'begin-login'
fetcherMock.mockReturnValueOnce(Promise.resolve({
url: "some url with url encoded at the end?return=hello"
}))
fetcherMock.mockReturnValueOnce(
Promise.resolve({
url: 'some url with url encoded at the end?return=hello',
})
)
// 'init-shibboleth-login'
fetcherMock.mockReturnValueOnce(Promise.resolve({
url: "some url with url encoded at the end?Target=hello"
}))
fetcherMock.mockReturnValueOnce(
Promise.resolve({
url: 'some url with url encoded at the end?Target=hello',
})
)
// 'init-bankId'
fetcherMock.mockReturnValueOnce(Promise.resolve({
text: jest.fn().mockReturnValue(Promise.resolve(`
fetcherMock.mockReturnValueOnce(
Promise.resolve({
text: jest.fn().mockReturnValue(
Promise.resolve(`
<html>
<body>
<input name="RelayState" value="aUUID"></input>
<input name="SAMLRequest" value="somebase64value"></input>
</body>
</html>`))
}))
</html>`)
),
})
)
// 'pick-mvghost'
fetcherMock.mockReturnValueOnce(Promise.resolve({
url: "some url to a mvghost"
}))
fetcherMock.mockReturnValueOnce(
Promise.resolve({
url: 'some url to a mvghost',
})
)
// 'start-bankId'
fetcherMock.mockReturnValueOnce(Promise.resolve({
url: "some base url to a mvghost to use when polling status"
}))
fetcherMock.mockReturnValueOnce(
Promise.resolve({
url: 'some base url to a mvghost to use when polling status',
})
)
}
const setupSuccessfullBankIdLogin = (fetcherMock: jest.Mock) => {
// 'poll-bankid-status'
fetcherMock.mockReturnValueOnce(Promise.resolve({
json: jest.fn().mockReturnValue(Promise.resolve({
infotext: "",
location: "an url to go to confirm the login"
}))
}))
fetcherMock.mockReturnValueOnce(
Promise.resolve({
json: jest.fn().mockReturnValue(
Promise.resolve({
infotext: '',
location: 'an url to go to confirm the login',
})
),
})
)
// 'confirm-signature-redirect'
fetcherMock.mockReturnValueOnce(Promise.resolve({
text: jest.fn().mockReturnValue(Promise.resolve(`
fetcherMock.mockReturnValueOnce(
Promise.resolve({
text: jest.fn().mockReturnValue(
Promise.resolve(`
<html>
<body>
<textarea name="RelayState">relay state probably same uuid as before</textarea>
<textarea name="SAMLResponse">base64 encoded saml response</textarea>
</body>
</html>`))
}))
</html>`)
),
})
)
// 'authgbg-saml-login'
fetcherMock.mockReturnValueOnce(Promise.resolve({
text: jest.fn().mockReturnValue(Promise.resolve(`
fetcherMock.mockReturnValueOnce(
Promise.resolve({
text: jest.fn().mockReturnValue(
Promise.resolve(`
<html>
<body>
<input name="RelayState" value="aUUID"></input>
<input name="SAMLResponse" value="somebase64value"></input>
</body>
</html>`))
}))
</html>`)
),
})
)
// 'hjarntorget-saml-login'
fetcherMock.mockReturnValueOnce(Promise.resolve({ status: 200 }))
@ -80,10 +103,13 @@ describe('api', () => {
fetcherMock = fetcher as jest.Mock
const cookieManager = wrapToughCookie(new CookieJar())
cookieManager.clearAll();
cookieManager.clearAll()
api = new ApiHjarntorget(jest.fn(), cookieManager)
api.replaceFetcher(fetcher)
})
it('works', () => {
expect(1 + 1).toBe(2)
})
// describe('#login', () => {
// it('goes through single sing-on steps', async (done) => {
// setupSuccessfullLoginInitiation(fetcherMock)

View File

@ -12,9 +12,9 @@
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/libs/api-skolplattformen"],
"outputs": ["coverage/libs/api-hjarntorget"],
"options": {
"jestConfig": "libs/api-skolplattformen/jest.config.js",
"jestConfig": "libs/api-hjarntorget/jest.config.js",
"passWithNoTests": true
}
}

View File

@ -0,0 +1 @@
import '@testing-library/jest-native/extend-expect'

View File

@ -0,0 +1,20 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"],
"composite": true
},
"include": [
"**/*.spec.ts",
"**/*.spec.tsx",
"**/*.spec.js",
"**/*.spec.jsx",
"**/*.test.ts",
"**/*.test.tsx",
"**/*.test.js",
"**/*.test.jsx",
"**/*.d.ts"
]
}

View File

@ -1,13 +1,6 @@
module.exports = {
displayName: 'api-skolplattformen',
preset: 'react-native',
resolver: '@nrwl/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'html', 'tsx', 'jsx'],
setupFilesAfterEnv: ['<rootDir>/test-setup.ts'],
transform: {
'\\.(js|ts|tsx)$': require.resolve('react-native/jest/preprocessor.js'),
'^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve(
'react-native/jest/assetFileTransformer.js'
),
},
};
}

View File

@ -1,9 +1,6 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
transform: {
'.(ts|tsx)': 'ts-jest',
},
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$',
moduleFileExtensions: ['ts', 'tsx', 'js'],
displayName: 'api-vklass',
resolver: '@nrwl/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'html', 'tsx', 'jsx'],
setupFilesAfterEnv: ['<rootDir>/test-setup.ts'],
}

View File

@ -14,20 +14,5 @@
"lint": "eslint 'lib/**/*.{js,ts}' --quiet --fix",
"test": "jest",
"build": "tsc --build"
},
"devDependencies": {
"@types/jest": "^26.0.22",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"eslint": "^7.24.0",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-config-prettier": "^8.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"ts-jest": "^26.5.5",
"typescript": "^4.2.4"
},
"dependencies": {}
}
}

View File

@ -12,7 +12,7 @@
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/libs/api-skolplattformen"],
"outputs": ["coverage/libs/api-vklass"],
"options": {
"jestConfig": "libs/api-vklass/jest.config.js",
"passWithNoTests": true

View File

@ -0,0 +1 @@
import '@testing-library/jest-native/extend-expect'

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,6 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
transform: {
'.(ts|tsx)': 'ts-jest',
},
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$',
moduleFileExtensions: ['ts', 'tsx', 'js'],
displayName: 'api',
resolver: '@nrwl/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'html', 'tsx', 'jsx'],
setupFilesAfterEnv: ['<rootDir>/test-setup.ts'],
}

1
libs/api/test-setup.ts Normal file
View File

@ -0,0 +1 @@
import '@testing-library/jest-native/extend-expect'