Skip to content

Commit 594de83

Browse files
committed
Getting coverage better
1 parent ef33df5 commit 594de83

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

src/appTemplates/AppClientAccount.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ class AppClientAccount extends Application {
4040
if (this.cache.collectorClientsMap[collectorClientKey]) {
4141
const collectorClient = this.cache.collectorClientsMap[collectorClientKey];
4242
logger.debug('AppClient:handleIncomingRequest found existing', { collectorClient });
43-
if (incomingEventId && collectorClient.requesterEventId !== incomingEventId) {
44-
throw new HDSLibError('Found existing collectorClient with a different eventId', { actual: collectorClient.requesterEventId, incoming: incomingEventId });
43+
if (collectorClient.requesterApiEndpoint !== apiEndpoint) {
44+
throw new HDSLibError('Found existing collectorClient with a different apiEndpoint', { actual: collectorClient.requesterApiEndpoint, incoming: apiEndpoint });
4545
// we might consider reseting() in the future;
4646
// return await collectorClient.reset(apiEndpoint, incomingEventId, accessInfo);
4747
}
48-
if (collectorClient.apiEndpoint !== apiEndpoint) {
49-
logger.error('Found existing collectorClient with a different apiEndpoint', { actual: collectorClient.requesterApiEndpoint, incoming: apiEndpoint });
48+
if (incomingEventId && collectorClient.requesterEventId !== incomingEventId) {
49+
throw new HDSLibError('Found existing collectorClient with a different eventId', { actual: collectorClient.requesterEventId, incoming: incomingEventId });
5050
// we might consider reseting() in the future;
5151
// return await collectorClient.reset(apiEndpoint, incomingEventId, accessInfo);
5252
}

tests/apptemplates.test.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ describe('[APTX] appTemplates', function () {
206206
const collectorClients = await myAppClient.getCollectorClients(true);
207207
assert.equal(collectorClients.length, 1);
208208

209+
// collectorClients can be retrieved by key
210+
const found = await myAppClient.getCollectorClientByKey(collectorClient.key);
211+
assert.equal(found, collectorClients[0]);
212+
209213
// check requestData
210214
assert.deepEqual(collectorClient.requestData, requestContent);
211215

@@ -294,9 +298,19 @@ describe('[APTX] appTemplates', function () {
294298
// revoke appManaging
295299
await new0.appManaging.connection.revoke();
296300
// create a new appManaging with the same name for the same user
297-
// const new1 = await helperNewAppManaging('dummy', 'dummyApp', new0.managingUser);
298-
// create a new invite for existing client
299-
// TODO
301+
const manager1 = await helperNewAppManaging('dummy', 'dummyApp', new0.managingUser);
302+
// get invites from precedent collector
303+
const collector1 = (await manager1.appManaging.getCollectors())[0];
304+
await collector1.init();
305+
const inv1 = (await collector1.getInvites())[0];
306+
const inviteSharingData1 = await inv1.getSharingData();
307+
// Already known but different incomingEnventId
308+
try {
309+
await new0.appClient.handleIncomingRequest(inviteSharingData1.apiEndpoint, inviteSharingData1.eventId);
310+
throw new Error('should throw Error');
311+
} catch (e) {
312+
assert.equal(e.message, 'Found existing collectorClient with a different apiEndpoint');
313+
}
300314
});
301315
});
302316

@@ -329,7 +343,8 @@ async function helperNewAppManaging (baseStreamIdManager, appName, managingUser
329343
if (!managingUser) {
330344
managingUser = await createUserAndPermissions(null, permissionsManager, initialStreams, appName);
331345
} else {
332-
await createUserPermissions(managingUser, permissionsManager, initialStreams, appName);
346+
// replace managing user with new permissions set
347+
managingUser = await createUserPermissions(managingUser, permissionsManager, initialStreams, appName);
333348
}
334349
const connection = new pryv.Connection(managingUser.appApiEndpoint);
335350
const appManaging = await AppManagingAccount.newFromConnection(baseStreamIdManager, connection);

0 commit comments

Comments
 (0)