Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should resolve with FALSE when called with an invalid permissionId', async () => {
const granted = await grantPermissions({ permissionId: 'unknownId' })(dispatch);
expect(granted).toBe(false);
expect(getAppPermissions).not.toHaveBeenCalled();
expect(requestAppPermissions).not.toHaveBeenCalled();
expect(dispatch).not.toHaveBeenCalled();
expect(openAppSettings).not.toHaveBeenCalled();
expect(event.addCallbackSpy).not.toHaveBeenCalled();
expect(logger.error).toHaveBeenCalledTimes(1);
});
it('should resolve with TRUE when the permissions are granted', async () => {
const granted = await grantPermissions({ permissionId })(dispatch);
expect(granted).toBe(true);
expect(getAppPermissions).toHaveBeenCalledWith([permissionId]);
expect(requestAppPermissions).not.toHaveBeenCalled();
expect(dispatch).not.toHaveBeenCalled();
expect(openAppSettings).not.toHaveBeenCalled();
expect(event.addCallbackSpy).not.toHaveBeenCalled();
});
it('should call the expected commands', () => {
callback({ dispatch });
expect(registerEvents).toHaveBeenCalledTimes(1);
expect(registerEvents).toHaveBeenCalledWith([
APP_EVENT_VIEW_DID_APPEAR,
APP_EVENT_VIEW_DID_DISAPPEAR,
]);
expect(event.addCallbackSpy).toHaveBeenCalledTimes(2);
expect(event.addCallbackSpy).toHaveBeenCalledWith(
APP_EVENT_VIEW_DID_APPEAR,
expect.any(Function)
);
expect(event.addCallbackSpy).toHaveBeenCalledWith(
APP_EVENT_VIEW_DID_DISAPPEAR,
expect.any(Function)
);
});
it('should call the expected commands', () => {
callback({ dispatch });
expect(registerEvents).toHaveBeenCalledTimes(1);
expect(registerEvents).toHaveBeenCalledWith([
APP_EVENT_VIEW_DID_APPEAR,
APP_EVENT_VIEW_DID_DISAPPEAR,
]);
expect(event.addCallbackSpy).toHaveBeenCalledTimes(2);
expect(event.addCallbackSpy).toHaveBeenCalledWith(
APP_EVENT_VIEW_DID_APPEAR,
expect.any(Function)
);
expect(event.addCallbackSpy).toHaveBeenCalledWith(
APP_EVENT_VIEW_DID_DISAPPEAR,
expect.any(Function)
);
});