UNPKG

@dossierhq/integration-test

Version:

Integration test to ensure that different Dossier database adapters work as expected.

27 lines 1.15 kB
/// <reference types="./TestAuthorizationAdapter.d.ts" /> import { notOk, ok } from '@dossierhq/core'; export function createTestAuthorizationAdapter() { return { resolveAuthorizationKeys(context, authKeys) { const result = []; for (const authKey of authKeys) { let resolvedAuthKey = authKey; if (authKey === 'subject') { if (!context.session.subjectId) { continue; } resolvedAuthKey = `subject:${context.session.subjectId}`; } else if (authKey === 'unauthorized') { return Promise.resolve(notOk.NotAuthorized(`User not authorized to use authKey ${authKey}`)); } else if (authKey === 'non-existing') { return Promise.resolve(notOk.BadRequest(`The authKey ${authKey} doesn't exist`)); } result.push({ authKey, resolvedAuthKey }); } return Promise.resolve(ok(result)); }, }; } //# sourceMappingURL=TestAuthorizationAdapter.js.map