Skip to content

Commit cdf27f7

Browse files
committed
Start adding interaction tests.
1 parent 815666a commit cdf27f7

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

852932
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)