-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from fga-gpp-mds/devel
US14 - Desativar conselheiros da aplicação
- Loading branch information
Showing
14 changed files
with
342 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
Oops, something went wrong.