Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Frigg CI #313

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 9 additions & 119 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 7 additions & 13 deletions packages/core/module-plugin/test/auther.test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
const {Api} = require('./mock-api/api');
const hubspotMocks = require('./mock-api/mocks/hubspot');

const { Definition } = require('./mock-api/definition');
const { Auther } = require('../auther');
const { mongoose } = require('../../database/mongoose');



const getModule = async (params) => {
const module = await Auther.getInstance({
definition: Definition,
userId: new mongoose.Types.ObjectId(),
...params,
});
module.api.getTokenFromCode = async function(code) {
module.api.getTokenFromCode = async function (code) {
await this.setTokens(hubspotMocks.tokenResponse);
return hubspotMocks.tokenResponse;
}
module.api.getUserDetails = async function() {
};
module.api.getUserDetails = async function () {
return hubspotMocks.userDetailsResponse;
}
return module
}

};
return module;
};

describe('HubSpot Module Tests', () => {
let module, authUrl;
Expand Down Expand Up @@ -58,7 +54,7 @@ describe('HubSpot Module Tests', () => {
expect(firstRes.entity_id).toBeDefined();
expect(firstRes.credential_id).toBeDefined();
});
it('retrieves existing entity on subsequent calls', async () =>{
it('retrieves existing entity on subsequent calls', async () => {
const response = hubspotMocks.authorizeResponse;
const res = await module.processAuthorizationCallback({
data: {
Expand All @@ -79,7 +75,6 @@ describe('HubSpot Module Tests', () => {
expect(newModule.entity).toBeDefined();
expect(newModule.credential).toBeDefined();
expect(await newModule.testAuth()).toBeTruthy();

});

it('retrieve by credential id', async () => {
Expand All @@ -91,7 +86,6 @@ describe('HubSpot Module Tests', () => {
expect(newModule).toBeDefined();
expect(newModule.credential).toBeDefined();
expect(await newModule.testAuth()).toBeTruthy();

});
});
});
6 changes: 2 additions & 4 deletions packages/core/module-plugin/test/mock-api/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { get } = require('../../assertions');
const { OAuth2Requester } = require('../../module-plugin');
const { get } = require('../../../assertions/get');
const { OAuth2Requester } = require('../../../module-plugin/index');

class Api extends OAuth2Requester {
constructor(params) {
Expand All @@ -22,8 +22,6 @@ class Api extends OAuth2Requester {
getAuthUri() {
return this.authorizationUri;
}


}

module.exports = { Api };
35 changes: 20 additions & 15 deletions packages/core/module-plugin/test/mock-api/definition.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
require('dotenv').config();
const {Api} = require('./api');
const {get} = require('../../assertions');
const config = {name: 'anapi'}
const { Api } = require('./api');
const { get } = require('../../../assertions/get');
const config = { name: 'anapi' };

const Definition = {
API: Api,
getName: function() {return config.name},
getName: function () {
return config.name;
},
moduleName: config.name,
modelName: 'AnApi',
requiredAuthMethods: {
getToken: async function(api, params){
getToken: async function (api, params) {
const code = get(params.data, 'code');
return api.getTokenFromCode(code);
},
getEntityDetails: async function(api, callbackParams, tokenResponse, userId) {
getEntityDetails: async function (
api,
callbackParams,
tokenResponse,
userId
) {
const userDetails = await api.getUserDetails();
return {
identifiers: { externalId: userDetails.portalId, user: userId },
details: { name: userDetails.hub_domain },
}
};
},
apiPropertiesToPersist: {
credential: [
'access_token', 'refresh_token'
],
credential: ['access_token', 'refresh_token'],
entity: [],
},
getCredentialDetails: async function(api, userId) {
getCredentialDetails: async function (api, userId) {
const userDetails = await api.getUserDetails();
return {
identifiers: { externalId: userDetails.portalId, user: userId },
details: {}
details: {},
};
},
testAuthRequest: async function(api){
return api.getUserDetails()
testAuthRequest: async function (api) {
return api.getUserDetails();
},
},
env: {
client_id: 'test',
client_secret: 'test',
scope: 'test',
redirect_uri: `http://localhost:3000/redirect/anapi`,
}
},
};

module.exports = { Definition };
4 changes: 3 additions & 1 deletion packages/test/Authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class Authenticator {
}
})
.listen(port, () => {
const options = browserName ? {app: {name: browserName }} : undefined
const options = browserName
? { app: { name: browserName } }
: undefined;
// open the browser to the authorize url to start the workflow
open(authorizeUrl, options).then((childProcess) => {
childProcess.unref();
Expand Down
Loading
Loading