@friggframework/devtools 1.1.1-canary.282.4de1ac1.0 → 1.2.0-canary.293.5731c31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@friggframework/devtools",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "1.1.1-canary.282.4de1ac1.0",
4
+ "version": "1.2.0-canary.293.5731c31.0",
5
5
  "dependencies": {
6
6
  "@babel/eslint-parser": "^7.18.9",
7
- "@friggframework/core": "1.1.1-canary.282.4de1ac1.0",
8
7
  "eslint": "^8.22.0",
9
8
  "eslint-config-prettier": "^8.5.0",
10
9
  "eslint-plugin-json": "^3.1.0",
@@ -37,5 +36,5 @@
37
36
  "publishConfig": {
38
37
  "access": "public"
39
38
  },
40
- "gitHead": "4de1ac138121295b795e1e9e0bb9e37bea2e8492"
39
+ "gitHead": "5731c31f2ef22a9b47b43a626cd8ff0e849bd561"
41
40
  }
@@ -5,9 +5,6 @@ const {
5
5
  } = require('./override-environment');
6
6
  const globalTeardown = require('./jest-global-teardown');
7
7
  const globalSetup = require('./jest-global-setup');
8
- const {testDefinitionRequiredAuthMethods} = require('./auther-definition-method-tester');
9
- const {createMockIntegration, createMockApiObject} = require('./mock-integration');
10
- const { testAutherDefinition } = require('./auther-definition-tester');
11
8
  const Authenticator = require('./Authenticator')
12
9
 
13
10
  module.exports = {
@@ -1,8 +1,6 @@
1
1
  const { TestMongo } = require('./mongodb');
2
- const { overrideEnvironment} = require('./override-environment');
3
2
 
4
3
  module.exports = async function () {
5
- overrideEnvironment({ STAGE: 'dev'})
6
4
  global.testMongo = new TestMongo();
7
5
  await global.testMongo.start();
8
6
  };
@@ -1,5 +1,3 @@
1
- const { restoreEnvironment } = require('./override-environment');
2
1
  module.exports = async function () {
3
- restoreEnvironment();
4
2
  await global.testMongo.stop();
5
3
  };
@@ -1,45 +0,0 @@
1
- const {flushDebugLog} = require('@friggframework/core');
2
-
3
- async function testDefinitionRequiredAuthMethods(api, definition, authCallbackParams, tokenResponse, userId) {
4
-
5
- // const response = await definition.getToken(api, authCallbackParams);
6
- // expect(api.setTokens).toHaveBeenCalled();
7
- // if (tokenResponse) {
8
- // expect(response).toMatchObject(tokenResponse);
9
- // }
10
-
11
- const entityDetails = await definition.requiredAuthMethods.getEntityDetails(api, authCallbackParams, tokenResponse, userId);
12
- expect(entityDetails).toHaveProperty('identifiers');
13
- expect(Object.values(entityDetails.identifiers).length).toBeGreaterThan(0);
14
- for (const key of Object.keys(entityDetails.identifiers)){
15
- expect(key).toBeDefined();
16
- expect(entityDetails.identifiers[key]).toBeDefined();
17
- }
18
-
19
-
20
- const credentialDetails = await definition.requiredAuthMethods.getCredentialDetails(api);
21
- expect(credentialDetails).toHaveProperty('identifiers');
22
- expect(Object.values(entityDetails.identifiers).length).toBeGreaterThan(0);
23
- for (const key of Object.keys(entityDetails.identifiers)){
24
- expect(key).toBeDefined();
25
- expect(entityDetails.identifiers[key]).toBeDefined();
26
- }
27
-
28
- const successResponse = await definition.requiredAuthMethods.testAuthRequest(api);
29
- expect(successResponse).toBeTruthy();
30
- const savedKeys = {};
31
- for (const key of definition.requiredAuthMethods.apiPropertiesToPersist.credential){
32
- savedKeys[key] = api[key];
33
- delete api[key];
34
- }
35
- let validAuth = false;
36
- try {
37
- if (await definition.requiredAuthMethods.testAuthRequest(api)) validAuth = true;
38
- } catch (e) {
39
- flushDebugLog(e);
40
- }
41
- expect(validAuth).not.toBeTruthy();
42
- Object.assign(api, savedKeys);
43
- }
44
-
45
- module.exports = { testDefinitionRequiredAuthMethods }
@@ -1,125 +0,0 @@
1
- const {
2
- Auther,
3
- ModuleConstants,
4
- createObjectId,
5
- connectToDatabase,
6
- disconnectFromDatabase,
7
- } = require('@friggframework/core');
8
- const { createMockApiObject } = require("./mock-integration");
9
-
10
-
11
- function testAutherDefinition(definition, mocks) {
12
- const getModule = async (params) => {
13
- const module = await Auther.getInstance({
14
- definition,
15
- userId: createObjectId(),
16
- ...params,
17
- });
18
- if (mocks.tokenResponse) {
19
- mocks.getTokenFrom = async function(code) {
20
- await this.setTokens(mocks.tokenResponse);
21
- return mocks.tokenResponse
22
- }
23
- mocks.getTokenFromCode = mocks.getTokenFromCode || mocks.getTokenFrom
24
- mocks.getTokenFromCodeBasicAuthHeader = mocks.getTokenFromCodeBasicAuthHeader || mocks.getTokenFrom
25
- mocks.getTokenFromClientCredentials = mocks.getTokenFromClientCredentials || mocks.getTokenFrom
26
- mocks.getTokenFromUsernamePassword = mocks.getTokenFromUsernamePassword || mocks.getTokenFrom
27
- }
28
- if (mocks.refreshResponse) {
29
- mocks.refreshAccessToken = async function(code) {
30
- await this.setTokens(mocks.refreshResponse);
31
- return mocks.refreshResponse
32
- }
33
- }
34
- module.api = createMockApiObject(jest, module.api, mocks);
35
- return module
36
- }
37
-
38
-
39
- describe(`${definition.moduleName} Module Tests`, () => {
40
- let module, authUrl;
41
- beforeAll(async () => {
42
- await connectToDatabase();
43
- module = await getModule();
44
- });
45
-
46
- afterAll(async () => {
47
- await disconnectFromDatabase();
48
- });
49
-
50
- let requirements, authCallbackParams;
51
- if (definition.API.requesterType === ModuleConstants.authType.oauth2) {
52
- authCallbackParams = mocks.authorizeResponse || mocks.authorizeParams;
53
- describe('getAuthorizationRequirements() test', () => {
54
- it('should return auth requirements', async () => {
55
- requirements = module.getAuthorizationRequirements();
56
- expect(requirements).toBeDefined();
57
- expect(requirements.type).toEqual(ModuleConstants.authType.oauth2);
58
- expect(requirements.url).toBeDefined();
59
- authUrl = requirements.url;
60
- });
61
- });
62
- } else if (definition.API.requesterType === ModuleConstants.authType.basic) {
63
- // could also confirm authCallbackParams against the auth requirements
64
- authCallbackParams = mocks.authorizeParams
65
- describe('getAuthorizationRequirements() test', () => {
66
- it('should return auth requirements', async () => {
67
- requirements = module.getAuthorizationRequirements();
68
- expect(requirements).toBeDefined();
69
- expect(requirements.type).toEqual(ModuleConstants.authType.basic);
70
- });
71
- });
72
- } else if (definition.API.requesterType === ModuleConstants.authType.apiKey) {
73
- // could also confirm authCallbackParams against the auth requirements
74
- authCallbackParams = mocks.authorizeParams
75
- describe('getAuthorizationRequirements() test', () => {
76
- it('should return auth requirements', async () => {
77
- requirements = module.getAuthorizationRequirements();
78
- expect(requirements).toBeDefined();
79
- expect(requirements.type).toEqual(ModuleConstants.authType.apiKey);
80
- });
81
- });
82
- }
83
-
84
- describe('Authorization requests', () => {
85
- let firstRes;
86
- it('processAuthorizationCallback()', async () => {
87
- firstRes = await module.processAuthorizationCallback(authCallbackParams);
88
- expect(firstRes).toBeDefined();
89
- expect(firstRes.entity_id).toBeDefined();
90
- expect(firstRes.credential_id).toBeDefined();
91
- });
92
- it('retrieves existing entity on subsequent calls', async () => {
93
- const res = await module.processAuthorizationCallback(authCallbackParams);
94
- expect(res).toEqual(firstRes);
95
- });
96
- });
97
-
98
- describe('Test credential retrieval and module instantiation', () => {
99
- it('retrieve by entity id', async () => {
100
- const newModule = await getModule({
101
- userId: module.userId,
102
- entityId: module.entity.id
103
- });
104
- expect(newModule).toBeDefined();
105
- expect(newModule.entity).toBeDefined();
106
- expect(newModule.credential).toBeDefined();
107
- expect(await newModule.testAuth()).toBeTruthy();
108
-
109
- });
110
-
111
- it('retrieve by credential id', async () => {
112
- const newModule = await getModule({
113
- userId: module.userId,
114
- credentialId: module.credential.id
115
- });
116
- expect(newModule).toBeDefined();
117
- expect(newModule.credential).toBeDefined();
118
- expect(await newModule.testAuth()).toBeTruthy();
119
- });
120
- });
121
- });
122
- }
123
-
124
- module.exports = { testAutherDefinition }
125
-
@@ -1,81 +0,0 @@
1
- const { Auther, Credential, Entity, IntegrationModel, mongoose } = require('@friggframework/core');
2
-
3
-
4
- async function createMockIntegration(IntegrationClassDef, userId = null, config = {},) {
5
- const integration = new IntegrationClassDef();
6
- userId = userId || new mongoose.Types.ObjectId();
7
- integration.delegateTypes.push(...IntegrationClassDef.Config.events)
8
-
9
- const insertOptions = {
10
- new: true,
11
- upsert: true,
12
- setDefaultsOnInsert: true,
13
- }
14
- const user = {user: userId}
15
-
16
- const credential = await Credential.findOneAndUpdate(
17
- user,
18
- { $set: user },
19
- insertOptions
20
- );
21
- const entity1 = await Entity.findOneAndUpdate(
22
- user,
23
- {
24
- $set: {
25
- credential: credential.id,
26
- user: userId,
27
- name: 'Test user',
28
- externalId: '1234567890123456',
29
- },
30
- },
31
- insertOptions
32
- );
33
- const entity2 = await Entity.findOneAndUpdate(
34
- user,
35
- {
36
- $set: {
37
- credential: credential.id,
38
- user: userId,
39
- },
40
- },
41
- insertOptions
42
- );
43
-
44
- const entities = [entity1, entity2]
45
- integration.record = await IntegrationModel.create({
46
- entities,
47
- user: userId,
48
- config: {type: IntegrationClassDef.Config.name, ...config}
49
- })
50
-
51
- integration.id = integration.record._id
52
-
53
- for (const i in entities){
54
- const [moduleName, ModuleDef] = Object.entries(IntegrationClassDef.modules)[i];
55
- const module = Auther.getInstance({definition: ModuleDef, userId: userId})
56
- module.entity = entities[i];
57
- integration[moduleName] = module;
58
- }
59
-
60
- return integration
61
- }
62
-
63
- function createMockApiObject(jest, api = {}, mockMethodMap) {
64
- // take in an api class and object with keys that are method names
65
- // and values which are the mock response (or implementation)
66
- const clone = (data) => JSON.parse(JSON.stringify(data));
67
-
68
- for (const [methodName, mockDataOrImplementation] of Object.entries(mockMethodMap)) {
69
- if (mockDataOrImplementation instanceof Function) {
70
- api[methodName] = jest.fn(mockDataOrImplementation);
71
- }
72
- else if (api[methodName]?.constructor?.name === "AsyncFunction") {
73
- api[methodName] = jest.fn().mockResolvedValue(clone(mockDataOrImplementation));
74
- } else {
75
- api[methodName] = jest.fn().mockReturnValue(clone(mockDataOrImplementation));
76
- }
77
- }
78
- return api;
79
- }
80
-
81
- module.exports = {createMockIntegration, createMockApiObject};