diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c8b7fe5..2fe1842 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,6 @@ name: react-native-template on: - pull_request_target: + pull_request: branches: [ master ] jobs: install-and-test: @@ -19,3 +19,15 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} threshold: 80 package-manager: yarn + - name: SonarQube Scan + uses: sonarsource/sonarqube-scan-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + + - uses: sonarsource/sonarqube-quality-gate-action@master + timeout-minutes: 5 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} diff --git a/app/navigators/AppNavigator.js b/app/navigators/appNavigator.js similarity index 85% rename from app/navigators/AppNavigator.js rename to app/navigators/appNavigator.js index d3baa1c..3ad9469 100644 --- a/app/navigators/AppNavigator.js +++ b/app/navigators/appNavigator.js @@ -3,7 +3,7 @@ import { createStackNavigator } from '@react-navigation/stack'; import SplashScreen from '@scenes/SplashScreen/'; import ExampleScreen from '@scenes/ExampleScreen'; import { NavigationContainer } from '@react-navigation/native'; -import NavigationService from '../services/NavigationService'; +import { setTopLevelNavigator } from '@services/navigationService'; const Stack = createStackNavigator(); /** * The root screen contains the application's navigation. @@ -12,7 +12,7 @@ const Stack = createStackNavigator(); */ export default function AppNavigator() { return ( - + diff --git a/app/scenes/ExampleScreen/saga.js b/app/scenes/ExampleScreen/saga.js index 618d25a..a0eefa1 100644 --- a/app/scenes/ExampleScreen/saga.js +++ b/app/scenes/ExampleScreen/saga.js @@ -1,6 +1,6 @@ import { put, call, takeLatest } from 'redux-saga/effects'; import { get } from 'lodash'; -import { getUser } from '@app/services/UserService'; +import { getUser } from '@app/services/userService'; import { exampleScreenActions, exampleScreenTypes } from './reducer'; /** diff --git a/app/scenes/ExampleScreen/tests/saga.test.js b/app/scenes/ExampleScreen/tests/saga.test.js index 5745a97..afb028f 100644 --- a/app/scenes/ExampleScreen/tests/saga.test.js +++ b/app/scenes/ExampleScreen/tests/saga.test.js @@ -5,7 +5,7 @@ /* eslint-disable redux-saga/yield-effects */ import { takeLatest, call, put } from 'redux-saga/effects'; -import { getUser } from 'app/services/UserService'; +import { getUser } from 'app/services/userService'; import { apiResponseGenerator } from 'app/utils/testUtils'; import exampleScreenSaga, { fetchUser } from '../saga'; import { exampleScreenTypes } from '../reducer'; diff --git a/app/scenes/RootScreen/index.js b/app/scenes/RootScreen/index.js index 1351e91..e27e26a 100644 --- a/app/scenes/RootScreen/index.js +++ b/app/scenes/RootScreen/index.js @@ -1,9 +1,9 @@ import { connect } from 'react-redux'; import { PropTypes } from 'prop-types'; -import AppNavigator from '@navigators/AppNavigator'; +import AppNavigator from '@navigators/appNavigator'; import Container from '@atoms/Container'; import React, { useEffect } from 'react'; -import { setRefForTopLevelNavigtor } from '@app/services/NavigationService'; +import { setRefForTopLevelNavigtor } from '@app/services/navigationService'; import { rootScreenActions } from './reducer'; const RootScreen = props => { diff --git a/app/scenes/RootScreen/saga.js b/app/scenes/RootScreen/saga.js index e9fa3e9..3df8651 100644 --- a/app/scenes/RootScreen/saga.js +++ b/app/scenes/RootScreen/saga.js @@ -1,5 +1,5 @@ import { takeLatest } from 'redux-saga/effects'; -import { navigateAndReset } from '@app/services/NavigationService'; +import { navigateAndReset } from '@app/services/navigationService'; import { rootScreenTypes } from './reducer'; /** diff --git a/app/scenes/RootScreen/tests/saga.test.js b/app/scenes/RootScreen/tests/saga.test.js index 0bed1dc..23143a1 100644 --- a/app/scenes/RootScreen/tests/saga.test.js +++ b/app/scenes/RootScreen/tests/saga.test.js @@ -5,7 +5,7 @@ /* eslint-disable redux-saga/yield-effects */ import { takeLatest } from 'redux-saga/effects'; -import NavigationService from 'app/services/NavigationService'; +import { setTopLevelNavigator } from 'app/services/navigationService'; import { timeout } from 'app/utils/testUtils'; import rootScreenSaga, { startup } from '../saga'; import { rootScreenTypes } from '../reducer'; @@ -25,17 +25,17 @@ describe('Tests for RootScreen sagas', () => { ); }); - it('should ensure that the navigation service is called after waiting for 1000ms', async () => { + it('should ensure that the navigation service is called after waiting for 1000ms11', async () => { const method = startup(); - NavigationService.navigateAndReset = submitSpy; + setTopLevelNavigator({ dispatch: submitSpy }); method.next(); - await timeout(1000); + await timeout(2000); expect(submitSpy).toHaveBeenCalled(); }); it('should ensure that the navigation service is called after waiting for 1000ms', async () => { const method = startup(); - NavigationService.navigateAndReset = submitSpy; + setTopLevelNavigator({ dispatch: submitSpy }); method.next(); await timeout(650); expect(submitSpy).not.toHaveBeenCalled(); diff --git a/app/services/NavigationService.js b/app/services/navigationService.js similarity index 86% rename from app/services/NavigationService.js rename to app/services/navigationService.js index 49c90a2..3bfe938 100644 --- a/app/services/NavigationService.js +++ b/app/services/navigationService.js @@ -11,7 +11,7 @@ let navigator; /** * This function is called when the RootScreen is created to set the navigator instance to use. */ -function setTopLevelNavigator(navigatorRef) { +export function setTopLevelNavigator(navigatorRef) { navigator = navigatorRef; } @@ -21,7 +21,7 @@ function setTopLevelNavigator(navigatorRef) { * @param routeName The name of the route to navigate to. Routes are defined in RootScreen using createStackNavigator() * @param params Route parameters. */ -function navigate(routeName, params) { +export function navigate(routeName, params) { navigator.dispatch( NavigationActions.navigate({ routeName, @@ -39,7 +39,7 @@ function navigate(routeName, params) { * @param routeName The name of the route to navigate to. Routes are defined in RootScreen using createStackNavigator() * @param params Route parameters. */ -function navigateAndReset(routeName, params) { +export function navigateAndReset(routeName, params) { navigator.dispatch( StackActions.replace({ routeName, @@ -47,9 +47,3 @@ function navigateAndReset(routeName, params) { }) ); } - -export default { - navigate, - navigateAndReset, - setTopLevelNavigator -}; diff --git a/app/services/UserService.js b/app/services/userService.js similarity index 100% rename from app/services/UserService.js rename to app/services/userService.js diff --git a/app/services/UserService.test.js b/app/services/userService.test.js similarity index 94% rename from app/services/UserService.test.js rename to app/services/userService.test.js index 53cbead..270b8a6 100644 --- a/app/services/UserService.test.js +++ b/app/services/userService.test.js @@ -1,6 +1,6 @@ import MockAdapter from 'axios-mock-adapter'; import { getApiClient } from 'app/utils/apiUtils'; -import { getUser } from './UserService'; +import { getUser } from './userService'; describe('UserService tests', () => { it('should make the api call to "/quotes?count=1"', async () => { diff --git a/index.js b/index.js new file mode 100644 index 0000000..1d6e981 --- /dev/null +++ b/index.js @@ -0,0 +1,8 @@ +import { registerRootComponent } from 'expo'; + +import App from './App'; + +// registerRootComponent calls AppRegistry.registerComponent('main', () => App); +// It also ensures that whether you load the app in Expo Go or in a native build, +// the environment is set up appropriately +registerRootComponent(App); diff --git a/metro.config.js b/metro.config.js new file mode 100644 index 0000000..9430b0f --- /dev/null +++ b/metro.config.js @@ -0,0 +1,4 @@ +// Learn more https://docs.expo.io/guides/customizing-metro +const { getDefaultConfig } = require('expo/metro-config'); + +module.exports = getDefaultConfig(__dirname);