Skip to content

Commit ef33df5

Browse files
committed
Refactoring test suite
1 parent e2be95c commit ef33df5

9 files changed

Lines changed: 415 additions & 192 deletions

File tree

src/appTemplates/AppClientAccount.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ class AppClientAccount extends Application {
4141
const collectorClient = this.cache.collectorClientsMap[collectorClientKey];
4242
logger.debug('AppClient:handleIncomingRequest found existing', { collectorClient });
4343
if (incomingEventId && collectorClient.requesterEventId !== incomingEventId) {
44-
logger.error('Found existing collectorClient with a different eventId', { actual: collectorClient.requesterEventId, incoming: incomingEventId });
45-
return await collectorClient.reset(apiEndpoint, incomingEventId, accessInfo);
44+
throw new HDSLibError('Found existing collectorClient with a different eventId', { actual: collectorClient.requesterEventId, incoming: incomingEventId });
45+
// we might consider reseting() in the future;
46+
// return await collectorClient.reset(apiEndpoint, incomingEventId, accessInfo);
4647
}
4748
if (collectorClient.apiEndpoint !== apiEndpoint) {
4849
logger.error('Found existing collectorClient with a different apiEndpoint', { actual: collectorClient.requesterApiEndpoint, incoming: apiEndpoint });
49-
return await collectorClient.reset(apiEndpoint, incomingEventId, accessInfo);
50+
// we might consider reseting() in the future;
51+
// return await collectorClient.reset(apiEndpoint, incomingEventId, accessInfo);
5052
}
5153
return collectorClient;
5254
}

src/appTemplates/Application.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ async function createAppStreams (app) {
146146
{ method: 'streams.create', params: { id: app.baseStreamId, name: app.appName, parentId: 'applications' } }
147147
];
148148
const streamCreateResult = await app.connection.api(apiCalls);
149+
for (const r of streamCreateResult) {
150+
if (r.error) throw new Error('Failed creating app streams', { apiCalls, streamCreateResult });
151+
}
149152
const stream = streamCreateResult[1].stream;
150153
app.cache.streamData = stream;
151154
}

src/patchedPryv.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (!pryv.Connection.prototype.apiOne) {
1515
* @param {string} [resultKey] - if given, returns the value or throws an error if not present
1616
* @throws {Error} if .error is present the response
1717
*/
18-
pryv.Connection.prototype.apiOne = async function (method, params = {}, expectedKey) {
18+
pryv.Connection.prototype.apiOne = async function apiOne (method, params = {}, expectedKey) {
1919
const result = await this.api([{ method, params }]);
2020
if (result[0] == null || result[0].error || (expectedKey != null && result[0][expectedKey] == null)) {
2121
const innerObject = result[0]?.error || result;
@@ -26,6 +26,35 @@ if (!pryv.Connection.prototype.apiOne) {
2626
if (expectedKey != null) return result[0][expectedKey];
2727
return result[0];
2828
};
29+
30+
/**
31+
* Revoke : Delete the accessId
32+
* - Do not thow error if access is already revoked, just return null;
33+
* @param {boolean} [throwOnFail = true] - if set to false do not throw Error on failure
34+
* @param {Connection} [usingConnection] - specify which connection issues the revoke, might be necessary when selfRovke
35+
*/
36+
pryv.Connection.prototype.revoke = async function revoke (throwOnFail = true, usingConnection) {
37+
usingConnection = usingConnection || this;
38+
let accessInfo = null;
39+
// get accessId
40+
try {
41+
accessInfo = await this.accessInfo();
42+
} catch (e) {
43+
if (e.response?.body?.error?.id === 'invalid-access-token') {
44+
return null; // Already revoked OK..
45+
}
46+
if (throwOnFail) throw e;
47+
return null;
48+
}
49+
// delete access
50+
try {
51+
const result = usingConnection.apiOne('accesses.delete', { id: accessInfo.id });
52+
return result;
53+
} catch (e) {
54+
if (throwOnFail) throw e;
55+
return null;
56+
}
57+
};
2958
}
3059

3160
module.exports = pryv;

0 commit comments

Comments
 (0)