@engage_so/core 2.2.0 → 2.2.2

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.
@@ -1,133 +0,0 @@
1
- import * as Engage from '../src/index'
2
-
3
- describe('Function Overloads', () => {
4
- beforeEach(() => {
5
- // Initialize SDK before each test
6
- Engage.init({ key: 'test-key', secret: 'test-secret' })
7
- })
8
-
9
- describe('Identify and stored user ID', () => {
10
- test('should store user ID when identify is called', async () => {
11
- await expect(Engage.identify({ id: 'test-user-123', email: 'test@example.com' }))
12
- .resolves.toMatchObject({ error: expect.any(String) })
13
- })
14
- })
15
-
16
- describe('addAttribute overloads', () => {
17
- test('should work with uid parameter', async () => {
18
- await expect(Engage.addAttribute('test-user-123', { name: 'John' }))
19
- .resolves.toMatchObject({ error: expect.any(String) })
20
- })
21
-
22
- test('should work without uid parameter after identify', async () => {
23
- // First identify to store user ID
24
- await Engage.identify({ id: 'test-user-123', email: 'test@example.com' })
25
-
26
- // Then use addAttribute without uid
27
- await expect(Engage.addAttribute({ name: 'John' }))
28
- .resolves.toMatchObject({ error: expect.any(String) })
29
- })
30
-
31
- test('should throw error if no stored uid and no uid provided', async () => {
32
- // Reset any stored user ID by re-initializing
33
- Engage.init({ key: 'test-key', secret: 'test-secret' })
34
-
35
- await expect(Engage.addAttribute({ name: 'John' }))
36
- .rejects.toThrow('User ID missing. Call identify() first or provide a uid parameter.')
37
- })
38
- })
39
-
40
- describe('track overloads', () => {
41
- test('should work with uid parameter', async () => {
42
- await expect(Engage.track('test-user-123', { event: 'login' }))
43
- .resolves.toMatchObject({ error: expect.any(String) })
44
- })
45
-
46
- test('should work without uid parameter after identify', async () => {
47
- // First identify to store user ID
48
- await Engage.identify({ id: 'test-user-123', email: 'test@example.com' })
49
-
50
- // Then use track without uid
51
- await expect(Engage.track({ event: 'login' }))
52
- .resolves.toMatchObject({ error: expect.any(String) })
53
- })
54
-
55
- test('should throw error if no stored uid and no uid provided', async () => {
56
- // Reset any stored user ID by re-initializing
57
- Engage.init({ key: 'test-key', secret: 'test-secret' })
58
-
59
- await expect(Engage.track({ event: 'login' }))
60
- .rejects.toThrow('User ID missing. Call identify() first or provide a uid parameter.')
61
- })
62
- })
63
-
64
- describe('convertToCustomer overloads', () => {
65
- test('should work with uid parameter', async () => {
66
- await expect((Engage.convertToCustomer as any)('test-user-123'))
67
- .resolves.toMatchObject({ error: expect.any(String) })
68
- })
69
-
70
- test('should work without uid parameter after identify', async () => {
71
- // First identify to store user ID
72
- await Engage.identify({ id: 'test-user-123', email: 'test@example.com' })
73
-
74
- // Then use convertToCustomer without uid
75
- await expect(Engage.convertToCustomer())
76
- .resolves.toMatchObject({ error: expect.any(String) })
77
- })
78
-
79
- test('should throw error if no stored uid and no uid provided', async () => {
80
- // Reset any stored user ID by re-initializing
81
- Engage.init({ key: 'test-key', secret: 'test-secret' })
82
-
83
- await expect(Engage.convertToCustomer())
84
- .rejects.toThrow('User ID missing. Call identify() first or provide a uid parameter.')
85
- })
86
- })
87
-
88
- describe('merge overloads', () => {
89
- test('should work with both source and destination uid', async () => {
90
- await expect(Engage.merge('source-user', 'dest-user'))
91
- .resolves.toMatchObject({ error: expect.any(String) })
92
- })
93
-
94
- test('should work with destination uid only after identify', async () => {
95
- // First identify to store user ID (source)
96
- await Engage.identify({ id: 'source-user', email: 'test@example.com' })
97
-
98
- // Then merge with destination only
99
- await expect(Engage.merge('dest-user'))
100
- .resolves.toMatchObject({ error: expect.any(String) })
101
- })
102
-
103
- test('should throw error if no stored uid and only destination provided', async () => {
104
- // Reset any stored user ID by re-initializing
105
- Engage.init({ key: 'test-key', secret: 'test-secret' })
106
-
107
- await expect(Engage.merge('dest-user'))
108
- .rejects.toThrow('User ID missing. Call identify() first or provide a uid parameter.')
109
- })
110
- })
111
-
112
- describe('account management overloads', () => {
113
- test('removeFromAccount should work with both signatures', async () => {
114
- await expect(Engage.removeFromAccount('user-id', 'account-id'))
115
- .resolves.toMatchObject({ error: expect.any(String) })
116
-
117
- // After identify
118
- await Engage.identify({ id: 'user-id', email: 'test@example.com' })
119
- await expect(Engage.removeFromAccount('account-id'))
120
- .resolves.toMatchObject({ error: expect.any(String) })
121
- })
122
-
123
- test('changeAccountRole should work with both signatures', async () => {
124
- await expect(Engage.changeAccountRole('user-id', 'account-id', 'owner'))
125
- .resolves.toMatchObject({ error: expect.any(String) })
126
-
127
- // After identify
128
- await Engage.identify({ id: 'user-id', email: 'test@example.com' })
129
- await expect(Engage.changeAccountRole('account-id', 'owner'))
130
- .resolves.toMatchObject({ error: expect.any(String) })
131
- })
132
- })
133
- })
@@ -1,121 +0,0 @@
1
- import * as Engage from '../src/index'
2
- import EngageSDK from '../src/index'
3
-
4
- describe('Method Overriding', () => {
5
- describe('Individual function exports', () => {
6
- test('should allow access to original init function', () => {
7
- expect(() => {
8
- Engage.init('test-key')
9
- }).not.toThrow()
10
- })
11
-
12
- test('should allow method overriding by replacing function', async () => {
13
- // Save original function
14
- const originalTrack = Engage.track
15
-
16
- // Create a mock function to override with
17
- const customTrack = jest.fn().mockImplementation(async (uidOrData: any, data?: any) => {
18
- // Call original function for proper behavior
19
- const result = await originalTrack(uidOrData, data)
20
- // Add custom flag to result
21
- return { ...result, customFlag: 'overridden' }
22
- })
23
-
24
- // Override the function
25
- ;(Engage as any).track = customTrack
26
-
27
- // Test the overridden function
28
- try {
29
- const result = await (Engage as any).track('user123', { event: 'test-event' })
30
- expect(result).toHaveProperty('customFlag', 'overridden')
31
- expect(customTrack).toHaveBeenCalledWith('user123', { event: 'test-event' })
32
- } catch (error) {
33
- // Expected to fail due to API authentication, but should still call our custom function
34
- expect(customTrack).toHaveBeenCalledWith('user123', { event: 'test-event' })
35
- }
36
-
37
- // Restore original function
38
- ;(Engage as any).track = originalTrack
39
- })
40
-
41
- test('should maintain function reference integrity', () => {
42
- const trackFunction = Engage.track
43
- expect(typeof trackFunction).toBe('function')
44
- expect(trackFunction).toBe(Engage.track)
45
- })
46
- })
47
-
48
- describe('Default export overriding', () => {
49
- test('should work with default export init', () => {
50
- expect(() => {
51
- EngageSDK.init('test-key-2')
52
- }).not.toThrow()
53
- })
54
-
55
- test('should allow method overriding on default export', async () => {
56
- // Save original function
57
- const originalIdentify = EngageSDK.identify
58
-
59
- // Create a mock function
60
- const customIdentify = jest.fn().mockImplementation(async (user: any) => {
61
- const result = await originalIdentify(user)
62
- return { ...result, customProcessed: true }
63
- })
64
-
65
- // Override the function
66
- ;(EngageSDK as any).identify = customIdentify
67
-
68
- // Test the overridden function
69
- try {
70
- const result = await (EngageSDK as any).identify({ id: 'test-user', email: 'test@example.com' })
71
- expect(result).toHaveProperty('customProcessed', true)
72
- expect(customIdentify).toHaveBeenCalledWith({ id: 'test-user', email: 'test@example.com' })
73
- } catch (error) {
74
- // Expected to fail due to API authentication, but should still call our custom function
75
- expect(customIdentify).toHaveBeenCalledWith({ id: 'test-user', email: 'test@example.com' })
76
- }
77
-
78
- // Restore original function
79
- ;(EngageSDK as any).identify = originalIdentify
80
- })
81
-
82
- test('should have consistent function references between named and default exports', () => {
83
- expect(typeof EngageSDK.init).toBe('function')
84
- expect(typeof EngageSDK.track).toBe('function')
85
- expect(typeof EngageSDK.identify).toBe('function')
86
- })
87
- })
88
-
89
- describe('Overriding behavior validation', () => {
90
- test('should allow chaining of overridden methods', async () => {
91
- const originalAddAttribute = Engage.addAttribute
92
-
93
- // First override
94
- const firstOverride = jest.fn().mockImplementation(async (uidOrAttrs: any, attrs?: any) => {
95
- const result = await (originalAddAttribute as any)(uidOrAttrs, attrs)
96
- return { ...result, step1: 'complete' }
97
- })
98
-
99
- // Second override that calls first override
100
- const secondOverride = jest.fn().mockImplementation(async (uidOrAttrs: any, attrs?: any) => {
101
- const result = await firstOverride(uidOrAttrs, attrs)
102
- return { ...result, step2: 'complete' }
103
- })
104
-
105
- ;(Engage as any).addAttribute = secondOverride
106
-
107
- try {
108
- await (Engage as any).addAttribute('test-user', { name: 'Test' })
109
- expect(secondOverride).toHaveBeenCalled()
110
- expect(firstOverride).toHaveBeenCalled()
111
- } catch (error) {
112
- // Expected to fail but should still call our functions
113
- expect(secondOverride).toHaveBeenCalled()
114
- expect(firstOverride).toHaveBeenCalled()
115
- }
116
-
117
- // Restore
118
- ;(Engage as any).addAttribute = originalAddAttribute
119
- })
120
- })
121
- })
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2015",
4
- "module": "NodeNext",
5
- "declaration": true,
6
- "declarationMap": true,
7
- "outDir": "./dist/",
8
- "esModuleInterop": true,
9
- "forceConsistentCasingInFileNames": true,
10
- "strict": true,
11
- "skipLibCheck": true
12
- },
13
- "exclude": [
14
- "node_modules",
15
- "tests"
16
- ]
17
- }