Skip to content

Commit 9118da2

Browse files
committed
Start adding interaction tests.
1 parent 2d57580 commit 9118da2

File tree

5 files changed

+95
-5
lines changed

5 files changed

+95
-5
lines changed

lib/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ cc(`${meterServiceName}.url`, () => `${bedrock.config.server.baseUri}/meters`);
4949
config.ensureConfigOverride.fields.push(meterServiceName);
5050

5151
// optional interaction config
52-
config.interactions = {
52+
cfg.interactions = {
5353
enabled: false,
5454
caches: {
5555
exchangePolling: {

lib/interactions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ bedrock.events.on('bedrock-express.configure.routes', app => {
113113
const localExchangeId = exchangeId.slice(exchangeId.lastIndexOf('/'));
114114
const id = `${config.server.baseUri}/${routes.interactions}/` +
115115
`${localInteractionId}/${localExchangeId}`;
116-
res.json({id, exchangeId});
116+
res.json({interactionId: id, exchangeId});
117117
}));
118118

119119
// gets an interaction by its "id"
120120
app.get(
121-
routes.interactionPath,
121+
routes.interaction,
122122
ensureAuthenticated,
123123
asyncHandler(async (req, res) => {
124124
const {id: accountId} = req.user.account || {};

schemas/bedrock-profile-http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const delegateCapability = {
165165
const createInteraction = {
166166
title: 'Create Interaction',
167167
type: 'object',
168-
required: ['workflowId', 'exchange'],
168+
required: ['workflowName', 'exchange'],
169169
additionalProperties: false,
170170
properties: {
171171
workflowName: {

test/mocha/10-api.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,86 @@ describe('bedrock-profile-http', () => {
845845
result.data.type.should.equal('NotAllowedError');
846846
});
847847
});
848+
describe('interactions', () => {
849+
// FIXME: create workflow instance
850+
// before()
851+
it('fails to create a new interaction with bad post data', async () => {
852+
let result;
853+
let error;
854+
try {
855+
result = await api.post('/interactions', {});
856+
} catch(e) {
857+
error = e;
858+
}
859+
assertNoError(error);
860+
should.exist(result);
861+
result.status.should.equal(400);
862+
result.ok.should.equal(false);
863+
result.data.message.should.equal(
864+
`A validation error occured in the 'Create Interaction' validator.`);
865+
});
866+
it('fails to create a new interaction with unknown workflow', async () => {
867+
let result;
868+
let error;
869+
try {
870+
result = await api.post('/interactions', {
871+
workflowName: 'does-not-exist',
872+
exchange: {
873+
variables: {}
874+
}
875+
});
876+
} catch(e) {
877+
error = e;
878+
}
879+
assertNoError(error);
880+
should.exist(result);
881+
result.status.should.equal(404);
882+
result.ok.should.equal(false);
883+
result.data.name.should.equal('NotFoundError');
884+
result.data.message.should.equal('Workflow "does-not-exist" not found.');
885+
});
886+
it.skip('creates a new interaction', async () => {
887+
let interactionId;
888+
{
889+
let result;
890+
let error;
891+
try {
892+
result = await api.post('/interactions', {
893+
workflowName: 'test',
894+
exchange: {
895+
variables: {}
896+
}
897+
});
898+
} catch(e) {
899+
error = e;
900+
}
901+
assertNoError(error);
902+
should.exist(result);
903+
result.status.should.equal(200);
904+
result.ok.should.equal(true);
905+
should.exist(result.data.interactionId);
906+
should.exist(result.data.exchangeId);
907+
interactionId = result.data.interactionId;
908+
}
909+
910+
// get status of interaction
911+
{
912+
let result;
913+
let error;
914+
try {
915+
result = await api.get(interactionId);
916+
} catch(e) {
917+
error = e;
918+
}
919+
assertNoError(error);
920+
should.exist(result);
921+
result.status.should.equal(200);
922+
result.ok.should.equal(true);
923+
console.log('result.data', result.data);
924+
// FIXME: assert on result.data
925+
}
926+
});
927+
});
848928
}); // end bedrock-profile-http
849929

850930
async function _createNProfiles({n, api, account, didMethod}) {

test/test.config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Copyright (c) 2020-2022 Digital Bazaar, Inc. All rights reserved.
2+
* Copyright (c) 2020-2024 Digital Bazaar, Inc. All rights reserved.
33
*/
44
import {config} from '@bedrock/core';
55
import {fileURLToPath} from 'node:url';
@@ -36,3 +36,13 @@ config['did-io'].methodOverrides.v1.disableFetch = true;
3636
config['profile-http'].additionalEdvs = {
3737
credentials: {referenceId: 'credentials'},
3838
};
39+
40+
// enable optional `interactions`
41+
config['profile-http'].interactions.enabled = true;
42+
config['profile-http'].interactions.workflows.test = {
43+
localInteractionId: '1d35d09b-94c8-44d5-9d10-8dd3460a5fc4',
44+
zcaps: {
45+
// FIXME:
46+
readWriteExchanges: '{}'
47+
}
48+
};

0 commit comments

Comments
 (0)