Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] check if authProvider is defined #3505

Merged
merged 5 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/ra-core/src/CoreAdminRouter.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,44 @@ describe('<AdminRouter>', () => {
});
});

describe('With no authProvider defined', () => {
it('should render all resources', () => {
const wrapper = shallow(
<CoreAdminRouter customRoutes={[]}>
<Resource name="posts" />
<Resource name="comments" />
</CoreAdminRouter>
);

const resources = wrapper.find('Connect(Resource)');

assert.equal(resources.length, 2);
assert.deepEqual(
resources.map(resource => resource.prop('context')),
['registration', 'registration']
);
});

it('should render all resources with a render prop', () => {
const wrapper = shallow(
<CoreAdminRouter>
{() => [
<Resource name="posts" />,
<Resource name="comments" />,
]}
</CoreAdminRouter>
);

const resources = wrapper.find('Connect(Resource)');

assert.equal(resources.length, 2);
assert.deepEqual(
resources.map(resource => resource.prop('context')),
['registration', 'registration']
);
});
});

describe('With resources returned from a function as children', () => {
it('should render all resources with a registration context', async () => {
const wrapper = shallow(
Expand Down
4 changes: 3 additions & 1 deletion packages/ra-core/src/CoreAdminRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export class CoreAdminRouter extends Component<
) => {
const { authProvider } = props;
try {
const permissions = await authProvider(AUTH_GET_PERMISSIONS);
const permissions = authProvider
? await authProvider(AUTH_GET_PERMISSIONS)
: undefined;
const resolveChildren = props.children as RenderResourcesFunction;

const childrenFuncResult = resolveChildren(permissions);
Expand Down