Skip to content

Commit

Permalink
Merge pull request #127 from fga-gpp-mds/devel
Browse files Browse the repository at this point in the history
US14 - Desativar conselheiros da aplicação
  • Loading branch information
AllanNobre authored Nov 25, 2017
2 parents da0b6b8 + 303e2ba commit 1f5e410
Show file tree
Hide file tree
Showing 14 changed files with 342 additions and 208 deletions.
7 changes: 1 addition & 6 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{
"presets": ["react-native"],
"env": {
"development": {
"plugins": ["transform-react-jsx-source"]
}
}
"presets": ["react-native", "react-native-dotenv"]
}
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
- run:
name: Style
command: npm run lint
- run:
name: Env variables
command: echo $'REACT_NATIVE_EMAIL=${REACT_NATIVE_EMAIL}\nREACT_NATIVE_PASS=${REACT_NATIVE_PASS}' > .env
- run: curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- run: chmod +x ./cc-test-reporter
- run: ./cc-test-reporter before-build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ coverage
*.swp
react-native-packager-cache-8324ab21a3f05848fbaec8ba15d56a326c9ba5f6/
haste-map-react-native-packager-1-3ee05e2fd5119494ef7365009e3d4a69
.env
1 change: 1 addition & 0 deletions __mocks__/react-native-router-flux.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export const Actions = {
profileInfoScreen: () => ({}),
schedulingVisit: () => ({}),
manageRegisters: () => ({}),
refresh: jest.fn(),
};
148 changes: 148 additions & 0 deletions __tests__/actions/manageRegistersActions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@

import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import * as actions from '../../src/actions/ManagerRegisterActions';
import * as types from '../../src/actions/types';
import {
COUNSELOR_DISABLED_SUCCESS,
DEFAULT_USER_LINK_NUVEM_CIVICA,
COUNSELOR_DISABLED_FAILED,
APP_IDENTIFIER,
AUTHENTICATE_LINK_NUVEM_CIVICA,
DEFAULT_GROUP_LINK_NUVEM_CIVICA,
COUNSELOR_GROUP_DISABLED_SUCCESS,
COUNSELOR_GROUP_DISABLED_FAILED,
} from '../../src/constants';


const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

const MASTER_TOKEN = 1;

const disableAppHeader = {
headers: {
appIdentifier: APP_IDENTIFIER,
appToken: MASTER_TOKEN,
},
};

const counselor = {
nuvemCode: 1,
};

const codGroup = '1';

describe('Testing manage registers actions', () => {
it('Test disableCounselorFromApp when disable is successfull', async () => {
const mock = new MockAdapter(axios);
mock.onDelete(
`${DEFAULT_USER_LINK_NUVEM_CIVICA}${counselor.nuvemCode}/perfil`).reply(200);

const actionReturn = await actions.disableCounselorFromApp(counselor, MASTER_TOKEN);
expect(actionReturn).toBe(COUNSELOR_DISABLED_SUCCESS);
});

it('Test disableCounselorFromApp when disable fails', async () => {
const mock = new MockAdapter(axios);
mock.onDelete(
`${DEFAULT_USER_LINK_NUVEM_CIVICA}2/perfil`,
disableAppHeader)
.reply(200);

try {
await actions.disableCounselorFromApp(counselor, MASTER_TOKEN);
} catch (e) {
expect(e).toEqual(COUNSELOR_DISABLED_FAILED);
}
});

it('Test authenticatingMasterCounselor when authentication is successfull', async () => {
const mock = new MockAdapter(axios);
mock.onGet(
`${AUTHENTICATE_LINK_NUVEM_CIVICA}`, disableAppHeader)
.reply(200, null, { apptoken: MASTER_TOKEN });

const response = await actions.authenticatingMasterCounselor();
expect(response).toEqual(MASTER_TOKEN);
});

it('Test authenticatingMasterCounselor when authentication fails', async () => {
const mock = new MockAdapter(axios);
mock.onGet(
`${AUTHENTICATE_LINK_NUVEM_CIVICA}`, { headers: { appIdentifier: 3 } });

try {
await actions.authenticatingMasterCounselor();
} catch (e) {
expect(e).toEqual('Não foi possível adquirir token para desassociação.');
}
});

it('Test disableCounselorFromGroup when disable is successfull', async () => {
const mock = new MockAdapter(axios);
mock.onDelete(
`${DEFAULT_GROUP_LINK_NUVEM_CIVICA}${codGroup}/membros/${counselor.codMembro}`).reply(200);

const actionReturn = await actions.disableCounselorFromGroup(counselor, codGroup, MASTER_TOKEN);

expect(actionReturn).toBe(COUNSELOR_GROUP_DISABLED_SUCCESS);
});

it('Test disableCounselorFromGroup when disable is unsuccessfull', async () => {
const mock = new MockAdapter(axios);
mock.onDelete(
`${DEFAULT_GROUP_LINK_NUVEM_CIVICA}${codGroup}/membros/${counselor.codMembro}`);

await actions.disableCounselorFromGroup(counselor, codGroup, MASTER_TOKEN)
.catch((message) => { expect(message).toBe(COUNSELOR_GROUP_DISABLED_FAILED); });
});

it('Test disable counselor from group when disable is successfull', async () => {
const mock = new MockAdapter(axios);
mock.onDelete(
`${DEFAULT_USER_LINK_NUVEM_CIVICA}${counselor.nuvemCode}/perfil`).reply(200);

mock.onGet(
`${AUTHENTICATE_LINK_NUVEM_CIVICA}`, disableAppHeader)
.reply(200, null, { apptoken: MASTER_TOKEN });

mock.onDelete(
`${DEFAULT_GROUP_LINK_NUVEM_CIVICA}${codGroup}/membros/${counselor.codMembro}`).reply(200);

const store = mockStore({});

jest.mock('react-native-router-flux');

const expectedPayload = {
type: types.RESET_LIST,
};

await store.dispatch(actions.disableCounselor(counselor, codGroup)).then(() => {
expect(store.getActions()).toEqual([expectedPayload]);
});
});

it('Test disable counselor from group when disable fails', async () => {
const mock = new MockAdapter(axios);

mock.onGet(
`${AUTHENTICATE_LINK_NUVEM_CIVICA}`, disableAppHeader)
.reply(200, null, { apptoken: MASTER_TOKEN });

mock.onDelete(
`${DEFAULT_GROUP_LINK_NUVEM_CIVICA}${codGroup}/membros/${counselor.codMembro}`).reply(200);

const store = mockStore({});

jest.mock('react-native-router-flux');


await store.dispatch(actions.disableCounselor(counselor, codGroup))
.catch((message) => {
expect(message).toBe(COUNSELOR_DISABLED_FAILED);
});
});
});
33 changes: 23 additions & 10 deletions __tests__/screens/ManageRegistersScreen.test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
import React from 'react';
import Enzyme, { shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
// import configureStore from 'redux-mock-store';
import ManageRegistersScreen from '../../src/screens/ManageRegistersScreen';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import ManageRegistersScreenContainer from '../../src/Containers/ManageRegistersScreenContainer';

Enzyme.configure({ adapter: new Adapter() });

// const mockStore = configureStore();
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

const props = {
listOfCounselorsInAGroup: [{ nome: 'Joao' }],
CAE: 'RO',
asyncGetCounselorFromGroup: jest.fn(),
const initialState = {
counselor: {
token: 1,
profile: {
cpf: '11111111111',
codGroup: '0',
CAE: 'RO',
},
},
list: {
listOfCounselorsInAGroup: [{ nome: 'Joao' }],
},
asyncGetCounselorFromGroup: 12312321,
};

const store = mockStore(initialState);

describe('Testing ManagerRegistersScreen', () => {
it('renders as expected', () => {
const wrapper = shallow(
<ManageRegistersScreen {...props} />,
);
expect(wrapper).toMatchSnapshot();
<ManageRegistersScreenContainer />,
{ context: { store } },
).dive();
});
});
Loading

0 comments on commit 1f5e410

Please sign in to comment.