UNPKG

cor-auth-service

Version:
130 lines (84 loc) 3.6 kB
'use strict'; import { CorAuthService } from "../src/CorAuthService"; import { exportAllDeclaration } from "@babel/types"; jest.mock('localforage') describe('Permissions', () => { test.skip('Obtaining user data', async () => { let auth_code = '1BeRIsdkLwrTzdJhhRXxgkj094OcwjwL0aQQ5klxmp6OmZ4dKsnGVPtFWOyHk2Cu'; let cor = new CorAuthService({auth_code: auth_code}); let result = null; await cor.get('v1/me') .then((res) => { result = res; }) .catch(err => { result = err }) expect(result).toEqual( expect.objectContaining({ id: expect.any(Number), email: expect.any(String), permissions: expect.any(Object) }), ); }); test.skip('Get Json permission from Persistence', async () => { localForage.get = jest.fn( () => { return { permissions: {}, access_type: {} } }); let permissions = await localForage.get('permissions'); expect(permissions).toEqual( expect.objectContaining({ permissions: expect.any(Object), access_type: expect.any(Object) }), ); }) test.skip('Get Boolean from function', async () => { let auth_code = '1BeRIsdkLwrTzdJhhRXxgkj094OcwjwL0aQQ5klxmp6OmZ4dKsnGVPtFWOyHk2Cu'; let cor = new CorAuthService({auth_code: auth_code}); let permissions = null; let result = null; await cor.get('v1/me') .then((res) => { permissions = res.permissions.permissions; }) .catch(err => { console.log(err); }) cor.checkPermissions = jest.fn( (entity, type) => { return permissions[entity] != undefined && permissions[entity][type] != undefined && permissions[entity][type]; }) result = cor.checkPermissions('notifications', 'delete'); expect(result).toEqual( expect.any(Boolean) ); }) test.skip('save permission', async () => { let auth_code = '1BeRIsdkLwrTzdJhhRXxgkj094OcwjwL0aQQ5klxmp6OmZ4dKsnGVPtFWOyHk2Cu'; let cor = new CorAuthService({auth_code: auth_code}); await new Promise(resolve => setTimeout(resolve, 2000)); expect(cor.permission_state).toBe(true) }) test.skip('get edit permissions for task entity', async () => { let auth_code = '1BeRIsdkLwrTzdJhhRXxgkj094OcwjwL0aQQ5klxmp6OmZ4dKsnGVPtFWOyHk2Cu'; let cor = new CorAuthService({auth_code: auth_code}); const permissions = await cor.checkPermissions('tasks','edit'); expect(permissions).toBe(true); }) test.skip('Reject permissions for edit quotation entity', async () => { let auth_code = '1BeRIsdkLwrTzdJhhRXxgkj094OcwjwL0aQQ5klxmp6OmZ4dKsnGVPtFWOyHk2Cu'; let cor = new CorAuthService({auth_code: auth_code}); const permissions = await cor.checkPermissions('quotations','edit'); expect(permissions).toBe(false); }) test.skip('Reject when entity is null or undefined', async () => { let auth_code = '1BeRIsdkLwrTzdJhhRXxgkj094OcwjwL0aQQ5klxmp6OmZ4dKsnGVPtFWOyHk2Cu'; let cor = new CorAuthService({auth_code: auth_code}); const permissions = await cor.checkPermissions(undefined, null); expect(permissions).toBe(false); }) });