Skip to content

Commit

Permalink
test: Add new tests, add new ESLint rules
Browse files Browse the repository at this point in the history
test: Fix code formatting according to ESLint in babel.config.js

Cover index.js with 100% code coverage. Refactoring of some unit tests. Add build stage before running tests. Fix code formatting by adding new ESLint rules.

Resolves: OKTA-355717 (#42)

OKTA-355717
<<<Jenkins Check-In of Tested SHA: e8c634c for [email protected]>>>
Artifact: okta-react-native
  • Loading branch information
oleggnidets-okta authored and eng-prod-CI-bot-okta committed Jan 28, 2021
1 parent 406cc42 commit e29eb5a
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 71 deletions.
30 changes: 30 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@ module.exports = {
],
rules: {
'semi': ['error', 'always'],
'indent': ['error', 2],
'no-var': 0,
'prefer-rest-params': 0,
'prefer-spread': 0,
'prefer-const': 0,
'node/no-unpublished-require': 0,
'node/no-unpublished-import': 0,
'camelcase': 2,
'complexity': [2, 7],
'curly': 2,
'dot-notation': 0,
'guard-for-in': 2,
'new-cap': [2, { 'properties': false }],
'no-caller': 2,
'no-empty': 2,
'no-eval': 2,
'no-implied-eval': 2,
'no-multi-str': 0,
'no-new': 2,
'no-plusplus': 0,
'no-undef': 2,
'no-unused-expressions': [2, { 'allowShortCircuit': true, 'allowTernary': true }],
'no-unused-vars': 2,
'max-depth': [2, 3],
'max-len': [2, 150],
'max-params': [2, 5],
'max-statements': [2, 25],
'quotes': [2, 'single', { 'allowTemplateLiterals': true }],
'strict': 0,
'wrap-iife': [2, 'any'],
},
overrides: [
{
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
.DS_Store
/test-reports
/dist
node_modules
npm-debug.log
yarn-error.*

.watchmanconfig

.vscode
!.vscode/launch.json

# android/ios related for react native
.gradle/
gradle/
Expand Down
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": [
"--runInBand"
],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true
}
]
}
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: ["@babel/plugin-transform-async-to-generator"]
plugins: ['@babel/plugin-transform-async-to-generator']
};
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const createConfig = async({
assertRedirectUri(endSessionRedirectUri);

const userAgentTemplate = `@okta/okta-react-native/${version} $UPSTREAM_SDK react-native/${version} ${Platform.OS}/${Platform.Version}`;
const { origin } = Url(discoveryUri);
const { origin } = new Url(discoveryUri);
authClient = new OktaAuth({
issuer: issuer || origin,
userAgent: {
Expand Down Expand Up @@ -106,12 +106,16 @@ export const getAuthClient = () => {
export const signIn = async(options) => {
// Custom sign in
if (options && typeof options === 'object') {
return authClient.signIn(options)
return getAuthClient().signIn(options)
.then((transaction) => {
const { status, sessionToken } = transaction;
if (status !== 'SUCCESS') {
throw new OktaStatusError('Transaction status other than "SUCCESS" has been returned. Check transaction.status and handle accordingly.', status);
throw new OktaStatusError(
'Transaction status other than "SUCCESS" has been returned. Check transaction.status and handle accordingly.',
status
);
}

return authenticate({ sessionToken });
})
.then(token => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
],
"restoreMocks": true,
"automock": false,
"preset": "react-native",
"preset": "./scripts/build.js",
"setupFiles": [
"./setupJest.js"
]
Expand All @@ -90,4 +90,4 @@
"outputDirectory": "./test-reports/unit/",
"outputName": "junit-result.xml"
}
}
}
Loading

0 comments on commit e29eb5a

Please sign in to comment.