Skip to content

Commit

Permalink
Merge pull request #1029 from bcgov/feature/declinedCredProblemReport
Browse files Browse the repository at this point in the history
Send problem report on reject cred in Tenant UI
  • Loading branch information
loneil authored Feb 23, 2024
2 parents e50f214 + 898b465 commit 6b5f7a2
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,15 @@ const rejectOffer = (event: any, data: V10CredentialExchange) => {
message: 'Are you sure you want to reject this credential offer?',
header: 'Confirmation',
icon: 'pi pi-exclamation-triangle',
accept: () => {
accept: async () => {
if (data.credential_exchange_id) {
// Send a problem report then delete the cred exchange record
await holderStore
.sendProblemReport(data.credential_exchange_id)
.catch((err: any) => {
console.error(`Problem report failed: ${err}`);
toast.error('Failure sending Problem Report');
});
holderStore
.deleteCredentialExchange(data.credential_exchange_id)
.then(() => {
Expand Down
4 changes: 2 additions & 2 deletions services/tenant-ui/frontend/src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export const API_PATH = {
ISSUE_CREDENTIALS_SEND_OFFER: '/issue-credential/send-offer',
ISSUE_CREDENTIAL_RECORDS_SEND_REQUEST: (id: string) =>
`/issue-credential/records/${id}/send-request`,
ISSUE_CREDENTIAL_RECORDS_PROBLEM_REPORT: (id: string) =>
`/issue-credential/records/${id}/problem-report`,

LEDGER_TAA: '/ledger/taa',
LEDGER_TAA_ACCEPT: '/ledger/taa/accept',
Expand Down Expand Up @@ -159,8 +161,6 @@ export const API_PATH = {
HOLDER_CREDENTIALS: '/tenant/v1/holder/credentials/',
HOLDER_CREDENTIALS_ACCEPT_OFFER: (id: string) =>
`/tenant/v1/holder/credentials/${id}/accept-offer`,
HOLDER_CREDENTIALS_REJECT_OFFER: (id: string) =>
`/tenant/v1/holder/credentials/${id}/reject-offer`,
HOLDER_CREDENTIAL: (id: string) => `/tenant/v1/holder/credentials/${id}`,
HOLDER_PRESENTATIONS: '/tenant/v1/holder/presentations/',
HOLDER_PRESENTATION: (id: string) => `/tenant/v1/holder/presentations/${id}`,
Expand Down
47 changes: 13 additions & 34 deletions services/tenant-ui/frontend/src/store/holderStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,39 +114,6 @@ export const useHolderStore = defineStore('holder', () => {
return result;
}

async function rejectCredentialOffer(credId: string) {
console.log('> holderStore.rejectCredentialOffer');

error.value = null;
loading.value = true;

const result = null;

// await acapyApi
// .postHttp(API_PATH.HOLDER_CREDENTIALS_REJECT_OFFER(credId), {
// holder_credential_id: credId,
// })
// .then((res) => {
// result = res.data.item;
// })
// .then(() => {
// console.log('credential offer rejected.');
// listCredentials(); // Refresh table
// })
// .catch((err) => {
// error.value = err;
// })
// .finally(() => {
// loading.value = false;
// });
// if (error.value != null) {
// // throw error so $onAction.onError listeners can add their own handler
// throw error.value;
// }
// return data so $onAction.after listeners can add their own handler
return result;
}

async function deleteCredentialExchange(credExId: string) {
console.log('> holderStore.deleteCredentialExchange');

Expand Down Expand Up @@ -178,6 +145,18 @@ export const useHolderStore = defineStore('holder', () => {
return result;
}

async function sendProblemReport(credExId: string) {
console.log('> holderStore.sendProblemReport');

await acapyApi
.postHttp(API_PATH.ISSUE_CREDENTIAL_RECORDS_PROBLEM_REPORT(credExId), {
description: 'Tenant rejected credential offer through Tenant UI.',
})
.then(() => {
console.log('Problem report sent.');
});
}

return {
credentialExchanges,
credentials,
Expand All @@ -197,7 +176,7 @@ export const useHolderStore = defineStore('holder', () => {
listHolderCredentialExchanges,
listOcas,
listPresentations,
rejectCredentialOffer,
sendProblemReport,
};
});

Expand Down
12 changes: 12 additions & 0 deletions services/tenant-ui/frontend/test/__mocks__/api/routes/holder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export const successHandlers = [
fullPathWithProxyTenant(API_PATH.ISSUE_CREDENTIAL_RECORD('test-id')),
() => HttpResponse.json({})
),
http.post(
fullPathWithProxyTenant(
API_PATH.ISSUE_CREDENTIAL_RECORDS_PROBLEM_REPORT('test-id')
),
() => HttpResponse.json({})
),
];

export const unknownErrorHandlers = [
Expand All @@ -34,4 +40,10 @@ export const unknownErrorHandlers = [
fullPathWithProxyTenant(API_PATH.ISSUE_CREDENTIAL_RECORD('test-id')),
() => HttpResponse.json({}, { status: 500 })
),
http.post(
fullPathWithProxyTenant(
API_PATH.ISSUE_CREDENTIAL_RECORDS_PROBLEM_REPORT('test-id')
),
() => HttpResponse.json({}, { status: 500 })
),
];
10 changes: 7 additions & 3 deletions services/tenant-ui/frontend/test/commonTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import { expect } from 'vitest';
const testSuccessResponse = async (
store: any,
func: () => void,
loadingKey: string
loadingKey: string | undefined
) => {
expect(store[loadingKey]).toEqual(true);
if (loadingKey) {
expect(store[loadingKey]).toEqual(true);
}
const response = await func;

expect(response).not.toBeNull();
expect(store[loadingKey]).toEqual(false);
if (loadingKey) {
expect(store[loadingKey]).toEqual(false);
}
expect(store.error).toBeNull();
};

Expand Down
16 changes: 13 additions & 3 deletions services/tenant-ui/frontend/test/store/holderStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { restHandlersUnknownError, server } from '../setupApi';

let store: any;

describe('connectionStore', () => {
describe('holderStore', () => {
beforeEach(async () => {
setActivePinia(createPinia());
store = useHolderStore();
Expand Down Expand Up @@ -42,6 +42,14 @@ describe('connectionStore', () => {
);
});

test('sendProblemReport does not throw exception', async () => {
await testSuccessResponse(
store,
store.sendProblemReport('test-id'),
undefined
);
});

// TODO: This doesn't seem to be used anywhere
test.todo('getCredential');
// TODO: This doesn't seem to be used anywhere
Expand All @@ -57,7 +65,6 @@ describe('connectionStore', () => {
test.todo('listHolderCredentialExchanges');
test.todo('listOcas');
test.todo('listPresentations');
test.todo('rejectCredentialOffer');
});

describe('Unsuccessful API calls', async () => {
Expand Down Expand Up @@ -85,9 +92,12 @@ describe('connectionStore', () => {
await expect(store.listCredentials()).rejects.toThrow();
});

test('sendProblemReport throws an error', async () => {
await expect(store.sendProblemReport('test-id')).rejects.toThrow();
});

test.todo('listHolderCredentialExchanges');
test.todo('listOcas');
test.todo('listPresentations');
test.todo('rejectCredentialOffer');
});
});

0 comments on commit 6b5f7a2

Please sign in to comment.