Respond to PR feedback.

This commit is contained in:
Kia Lam
2019-03-05 12:01:06 -05:00
parent 35ecd83214
commit 9f86fc2def
7 changed files with 101 additions and 135 deletions

View File

@@ -17,20 +17,14 @@ const mockResults = [
{
role: {
name: 'foo',
id: 2,
}
}
]
],
}
}
];
const mockUserRoles = [
{
id: 2,
name: 'bar',
}
];
describe('<AccessList />', () => {
test('initially renders succesfully', () => {
mount(
@@ -40,7 +34,6 @@ describe('<AccessList />', () => {
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '1' } }}
location={{ search: '', pathname: '/organizations/1/access' }}
getAccessList={() => {}}
getUserRoles={() => {}}
/>
</MemoryRouter>
</I18nProvider>
@@ -55,7 +48,6 @@ describe('<AccessList />', () => {
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '0' } }}
location={{ search: '', pathname: '/organizations/1/access' }}
getAccessList={() => ({ data: { count: 1, results: mockResults } })}
getUserRoles={() => ({ data: { results: mockUserRoles } })}
/>
</MemoryRouter>
</I18nProvider>
@@ -77,7 +69,6 @@ describe('<AccessList />', () => {
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '0' } }}
location={{ search: '', pathname: '/organizations/1/access' }}
getAccessList={() => ({ data: { count: 1, results: mockResults } })}
getUserRoles={() => ({ data: { results: mockUserRoles } })}
/>
</MemoryRouter>
</I18nProvider>
@@ -104,7 +95,6 @@ describe('<AccessList />', () => {
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '0' } }}
location={{ search: '', pathname: '/organizations/1/access' }}
getAccessList={() => ({ data: { count: 1, results: mockResults } })}
getUserRoles={() => ({ data: { results: mockUserRoles } })}
/>
</MemoryRouter>
</I18nProvider>
@@ -118,4 +108,53 @@ describe('<AccessList />', () => {
done();
});
});
test('getTeamRoles returns empty array if dataset is missing team_id attribute', (done) => {
const mockData = [
{
id: 1,
username: 'boo',
url: '/foo/bar/',
first_name: 'john',
last_name: 'smith',
summary_fields: {
foo: [
{
role: {
name: 'foo',
id: 2,
}
}
],
direct_access: [
{
role: {
name: 'team user',
id: 3,
}
}
]
}
}
];
const wrapper = mount(
<I18nProvider>
<MemoryRouter>
<AccessList
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '0' } }}
location={{ search: '', pathname: '/organizations/1/access' }}
getAccessList={() => ({ data: { count: 1, results: mockData } })}
/>
</MemoryRouter>
</I18nProvider>
).find('AccessList');
setImmediate(() => {
const { results } = wrapper.state();
results.forEach(result => {
expect(result.teamRoles).toEqual([]);
});
done();
});
});
});

View File

@@ -7,18 +7,11 @@ import OrganizationAccess from '../../../../../src/pages/Organizations/screens/O
const mockAPIAccessList = {
foo: 'bar',
};
const mockAPIRoles = {
bar: 'baz',
};
const mockGetOrganzationAccessList = jest.fn(() => (
Promise.resolve(mockAPIAccessList)
));
const mockGetUserRoles = jest.fn(() => (
Promise.resolve(mockAPIRoles)
));
describe('<OrganizationAccess />', () => {
test('initially renders succesfully', () => {
mount(
@@ -29,7 +22,6 @@ describe('<OrganizationAccess />', () => {
params={{}}
api={{
getOrganzationAccessList: jest.fn(),
getUserRoles: jest.fn(),
}}
/>
</MemoryRouter>
@@ -45,14 +37,11 @@ describe('<OrganizationAccess />', () => {
params={{}}
api={{
getOrganzationAccessList: mockGetOrganzationAccessList,
getUserRoles: mockGetUserRoles,
}}
/>
</MemoryRouter>
).find('OrganizationAccess');
const accessList = await wrapper.instance().getOrgAccessList();
expect(accessList).toEqual(mockAPIAccessList);
const userRoles = await wrapper.instance().getUserRoles();
expect(userRoles).toEqual(mockAPIRoles);
});
});