@maxzima/wa-communicator 1.0.9 → 1.0.10

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.
@@ -11,6 +11,7 @@ export declare class Communicator {
11
11
  getCurrentUserProfile(data: TGetCurrentUserProfileRequestData): Promise<TResponse>;
12
12
  registration(data: TRegistrationRequestData): Promise<TResponse>;
13
13
  private send;
14
+ private getHeaders;
14
15
  private getMeta;
15
16
  private processingQueryParams;
16
17
  }
@@ -2,6 +2,13 @@ import { __awaiter } from "tslib";
2
2
  import { CommunicatorDefaultRequestData } from "./../Constants/Communicator";
3
3
  export class Communicator {
4
4
  constructor(props) {
5
+ this.getHeaders = (token) => {
6
+ let headers = CommunicatorDefaultRequestData.FETCH_HEADERS_INIT;
7
+ if (token) {
8
+ headers = Object.assign(Object.assign({}, headers), { 'Authorization': `Bearer ${token}` });
9
+ }
10
+ return headers;
11
+ };
5
12
  this.getMeta = (browserData) => {
6
13
  return {
7
14
  audit_source_type: CommunicatorDefaultRequestData.AUDIT_SOURCE_TYPE,
@@ -32,6 +39,7 @@ export class Communicator {
32
39
  if (!data.browserData) {
33
40
  return;
34
41
  }
42
+ const headers = this.getHeaders();
35
43
  const meta = this.getMeta(data.browserData);
36
44
  const body = JSON.stringify({
37
45
  captcha_response: '_',
@@ -42,12 +50,13 @@ export class Communicator {
42
50
  method: 'POST',
43
51
  url: `${this.props.clientAuthApiBaseUrl}${"sign-in"}`,
44
52
  body,
45
- headers: CommunicatorDefaultRequestData.FETCH_HEADERS_INIT,
53
+ headers,
46
54
  });
47
55
  });
48
56
  }
49
57
  signUp(data) {
50
58
  return __awaiter(this, void 0, void 0, function* () {
59
+ const headers = this.getHeaders();
51
60
  const body = JSON.stringify({
52
61
  locale: data.locale,
53
62
  mobile: data.phoneNumber,
@@ -57,16 +66,17 @@ export class Communicator {
57
66
  method: 'POST',
58
67
  url: `${this.props.clientAuthApiBaseUrl}${"sign-up"}`,
59
68
  body,
60
- headers: CommunicatorDefaultRequestData.FETCH_HEADERS_INIT,
69
+ headers,
61
70
  });
62
71
  });
63
72
  }
64
73
  setupChallenge(data) {
65
74
  return __awaiter(this, void 0, void 0, function* () {
75
+ const headers = this.getHeaders(data.authToken);
66
76
  return yield this.send({
67
77
  method: 'GET',
68
78
  url: `${this.props.clientAuthApiBaseUrl}${"sign-in/challenge"}`,
69
- headers: Object.assign({ 'Authorization': `Bearer ${data.authToken}` }, CommunicatorDefaultRequestData.FETCH_HEADERS_INIT),
79
+ headers,
70
80
  queryParams: {
71
81
  type: data.type,
72
82
  },
@@ -75,6 +85,7 @@ export class Communicator {
75
85
  }
76
86
  verifyChallenge(data) {
77
87
  return __awaiter(this, void 0, void 0, function* () {
88
+ const headers = this.getHeaders(data.authToken);
78
89
  const body = JSON.stringify({
79
90
  type: data.type,
80
91
  value: data.code,
@@ -82,44 +93,48 @@ export class Communicator {
82
93
  return yield this.send({
83
94
  method: 'POST',
84
95
  url: `${this.props.clientAuthApiBaseUrl}${"sign-in/challenge"}`,
85
- headers: Object.assign({ 'Authorization': `Bearer ${data.authToken}` }, CommunicatorDefaultRequestData.FETCH_HEADERS_INIT),
96
+ headers,
86
97
  body,
87
98
  });
88
99
  });
89
100
  }
90
101
  emailUpdate(data) {
91
102
  return __awaiter(this, void 0, void 0, function* () {
103
+ const headers = this.getHeaders(data.authToken);
92
104
  const body = JSON.stringify({
93
105
  email: data.email,
94
106
  });
95
107
  return yield this.send({
96
108
  method: 'PATCH',
97
109
  url: `${this.props.clientAuthApiBaseUrl}${"sign-in/email"}`,
98
- headers: Object.assign({ 'Authorization': `Bearer ${data.authToken}` }, CommunicatorDefaultRequestData.FETCH_HEADERS_INIT),
110
+ headers,
99
111
  body,
100
112
  });
101
113
  });
102
114
  }
103
115
  createSession(data) {
104
116
  return __awaiter(this, void 0, void 0, function* () {
117
+ const headers = this.getHeaders(data.authToken);
105
118
  return yield this.send({
106
119
  method: 'POST',
107
120
  url: `${this.props.clientAuthApiBaseUrl}${"sign-in/session"}`,
108
- headers: Object.assign({ 'Authorization': `Bearer ${data.authToken}` }, CommunicatorDefaultRequestData.FETCH_HEADERS_INIT),
121
+ headers,
109
122
  });
110
123
  });
111
124
  }
112
125
  getCurrentUserProfile(data) {
113
126
  return __awaiter(this, void 0, void 0, function* () {
127
+ const headers = this.getHeaders(data.accessToken);
114
128
  return yield this.send({
115
129
  method: 'GET',
116
130
  url: `${this.props.clientFAPIBaseUrl}${"user"}`,
117
- headers: Object.assign({ 'Authorization': `Bearer ${data.accessToken}` }, CommunicatorDefaultRequestData.FETCH_HEADERS_INIT),
131
+ headers,
118
132
  });
119
133
  });
120
134
  }
121
135
  registration(data) {
122
136
  return __awaiter(this, void 0, void 0, function* () {
137
+ const headers = this.getHeaders(data.accessToken);
123
138
  const body = JSON.stringify({
124
139
  name: data.name,
125
140
  source: {
@@ -132,7 +147,7 @@ export class Communicator {
132
147
  return yield this.send({
133
148
  method: 'POST',
134
149
  url: `${this.props.clientFAPIBaseUrl}${"clients/registration"}`,
135
- headers: Object.assign({ 'Authorization': `Bearer ${data.accessToken}` }, CommunicatorDefaultRequestData.FETCH_HEADERS_INIT),
150
+ headers,
136
151
  body,
137
152
  });
138
153
  });
@@ -117,4 +117,4 @@ declare type TRegistrationRequestData = {
117
117
  gaId: TRegistrationRequestBodySource['ga_id'];
118
118
  origin: TRegistrationRequestBodySource['origin'];
119
119
  };
120
- export { TChallenge, TAuditSource, TRequestProps, TRequestQueryParams, TResponse, TSignInStartRequestBody, TAccountMeta, TAccountBrowserData, TSignInByMobileRequestData, TSignInByMobileResponse, TSignUpStartRequestBody, TSignUpByMobileRequestData, TSetupChallengeRequestData, TSetupChallengeResponse, TVerifyChallengeRequestBody, TVerifyChallengeRequestData, TVerifyChallengeResponse, TEmailUpdateRequestData, TCreateSessionRequestData, TCreateSessionResponse, TGetCurrentUserProfileResponseUser, TGetCurrentUserProfileRequestData, TRegistrationRequestData };
120
+ export { TRegistrationRequestBodySourceDeviceType, TChallenge, TAuditSource, TRequestProps, TRequestQueryParams, TResponse, TSignInStartRequestBody, TAccountMeta, TAccountBrowserData, TSignInByMobileRequestData, TSignInByMobileResponse, TSignUpStartRequestBody, TSignUpByMobileRequestData, TSetupChallengeRequestData, TSetupChallengeResponse, TVerifyChallengeRequestBody, TVerifyChallengeRequestData, TVerifyChallengeResponse, TEmailUpdateRequestData, TCreateSessionRequestData, TCreateSessionResponse, TGetCurrentUserProfileResponseUser, TGetCurrentUserProfileRequestData, TRegistrationRequestData };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.9",
2
+ "version": "1.0.10",
3
3
  "name": "@maxzima/wa-communicator",
4
4
  "description": "",
5
5
  "author": "Noname",
@@ -36,10 +36,10 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@size-limit/preset-small-lib": "8.2.4",
39
+ "@types/gtag.js": "0.0.10",
39
40
  "@types/jest": "28.1.8",
40
41
  "@typescript-eslint/eslint-plugin": "5.59.5",
41
42
  "@typescript-eslint/parser": "5.59.5",
42
- "@types/gtag.js": "0.0.10",
43
43
  "eslint": "8.40.0",
44
44
  "eslint-config-prettier": "8.8.0",
45
45
  "eslint-plugin-editorconfig": "4.0.3",
@@ -30,6 +30,7 @@ export class Communicator {
30
30
  return;
31
31
  }
32
32
 
33
+ const headers = this.getHeaders();
33
34
  const meta = this.getMeta(data.browserData);
34
35
  const body = JSON.stringify({
35
36
  captcha_response: '_',
@@ -41,11 +42,12 @@ export class Communicator {
41
42
  method: 'POST',
42
43
  url: `${this.props.clientAuthApiBaseUrl}${CommunicatorAuthAPIEndpointEnum.SIGN_IN}`,
43
44
  body,
44
- headers: CommunicatorDefaultRequestData.FETCH_HEADERS_INIT,
45
+ headers,
45
46
  });
46
47
  }
47
48
 
48
49
  public async signUp(data: TSignUpByMobileRequestData) {
50
+ const headers = this.getHeaders();
49
51
  const body = JSON.stringify({
50
52
  locale: data.locale,
51
53
  mobile: data.phoneNumber,
@@ -56,18 +58,17 @@ export class Communicator {
56
58
  method: 'POST',
57
59
  url: `${this.props.clientAuthApiBaseUrl}${CommunicatorAuthAPIEndpointEnum.SIGN_UP}`,
58
60
  body,
59
- headers: CommunicatorDefaultRequestData.FETCH_HEADERS_INIT,
61
+ headers,
60
62
  });
61
63
  }
62
64
 
63
65
  public async setupChallenge(data: TSetupChallengeRequestData) {
66
+ const headers = this.getHeaders(data.authToken);
67
+
64
68
  return await this.send({
65
69
  method: 'GET',
66
70
  url: `${this.props.clientAuthApiBaseUrl}${CommunicatorAuthAPIEndpointEnum.CHALLENGE}`,
67
- headers: {
68
- 'Authorization': `Bearer ${data.authToken}`,
69
- ...CommunicatorDefaultRequestData.FETCH_HEADERS_INIT,
70
- },
71
+ headers,
71
72
  queryParams: {
72
73
  type: data.type,
73
74
  },
@@ -75,6 +76,7 @@ export class Communicator {
75
76
  }
76
77
 
77
78
  public async verifyChallenge(data: TVerifyChallengeRequestData) {
79
+ const headers = this.getHeaders(data.authToken);
78
80
  const body = JSON.stringify({
79
81
  type: data.type,
80
82
  value: data.code,
@@ -83,15 +85,13 @@ export class Communicator {
83
85
  return await this.send({
84
86
  method: 'POST',
85
87
  url: `${this.props.clientAuthApiBaseUrl}${CommunicatorAuthAPIEndpointEnum.CHALLENGE}`,
86
- headers: {
87
- 'Authorization': `Bearer ${data.authToken}`,
88
- ...CommunicatorDefaultRequestData.FETCH_HEADERS_INIT,
89
- },
88
+ headers,
90
89
  body,
91
90
  });
92
91
  }
93
92
 
94
93
  public async emailUpdate(data: TEmailUpdateRequestData) {
94
+ const headers = this.getHeaders(data.authToken);
95
95
  const body = JSON.stringify({
96
96
  email: data.email,
97
97
  });
@@ -99,37 +99,33 @@ export class Communicator {
99
99
  return await this.send({
100
100
  method: 'PATCH',
101
101
  url: `${this.props.clientAuthApiBaseUrl}${CommunicatorAuthAPIEndpointEnum.EMAIL}`,
102
- headers: {
103
- 'Authorization': `Bearer ${data.authToken}`,
104
- ...CommunicatorDefaultRequestData.FETCH_HEADERS_INIT,
105
- },
102
+ headers,
106
103
  body,
107
104
  });
108
105
  }
109
106
 
110
107
  public async createSession(data: TCreateSessionRequestData) {
108
+ const headers = this.getHeaders(data.authToken);
109
+
111
110
  return await this.send({
112
111
  method: 'POST',
113
112
  url: `${this.props.clientAuthApiBaseUrl}${CommunicatorAuthAPIEndpointEnum.SESSION}`,
114
- headers: {
115
- 'Authorization': `Bearer ${data.authToken}`,
116
- ...CommunicatorDefaultRequestData.FETCH_HEADERS_INIT,
117
- },
113
+ headers,
118
114
  });
119
115
  }
120
116
 
121
117
  public async getCurrentUserProfile(data: TGetCurrentUserProfileRequestData) {
118
+ const headers = this.getHeaders(data.accessToken);
119
+
122
120
  return await this.send({
123
121
  method: 'GET',
124
122
  url: `${this.props.clientFAPIBaseUrl}${CommunicatorFAPIEndpointEnum.USER}`,
125
- headers: {
126
- 'Authorization': `Bearer ${data.accessToken}`,
127
- ...CommunicatorDefaultRequestData.FETCH_HEADERS_INIT,
128
- },
123
+ headers,
129
124
  });
130
125
  }
131
126
 
132
127
  public async registration(data: TRegistrationRequestData) {
128
+ const headers = this.getHeaders(data.accessToken);
133
129
  const body = JSON.stringify({
134
130
  name: data.name,
135
131
  source: {
@@ -143,10 +139,7 @@ export class Communicator {
143
139
  return await this.send({
144
140
  method: 'POST',
145
141
  url: `${this.props.clientFAPIBaseUrl}${CommunicatorFAPIEndpointEnum.REGISTRATION}`,
146
- headers: {
147
- 'Authorization': `Bearer ${data.accessToken}`,
148
- ...CommunicatorDefaultRequestData.FETCH_HEADERS_INIT,
149
- },
142
+ headers,
150
143
  body,
151
144
  });
152
145
  }
@@ -173,6 +166,19 @@ export class Communicator {
173
166
  });
174
167
  }
175
168
 
169
+ private getHeaders = (token?: string) => {
170
+ let headers = CommunicatorDefaultRequestData.FETCH_HEADERS_INIT
171
+
172
+ if (token) {
173
+ headers = {
174
+ ...headers,
175
+ 'Authorization': `Bearer ${token}`,
176
+ }
177
+ }
178
+
179
+ return headers;
180
+ }
181
+
176
182
  private getMeta = (browserData: TAccountBrowserData): TAccountMeta => {
177
183
  return {
178
184
  audit_source_type: CommunicatorDefaultRequestData.AUDIT_SOURCE_TYPE,
@@ -167,6 +167,7 @@ type TRegistrationRequestData = {
167
167
  /* endregion registration */
168
168
 
169
169
  export {
170
+ TRegistrationRequestBodySourceDeviceType,
170
171
  TChallenge,
171
172
  TAuditSource,
172
173
  TRequestProps,
@@ -0,0 +1,134 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Communicator getHeaders headers with token 1`] = `
4
+ Object {
5
+ "Accept": "application/json, text/plain, */*",
6
+ "Authorization": "Bearer _token_",
7
+ "Content-Type": "application/json",
8
+ }
9
+ `;
10
+
11
+ exports[`Communicator getHeaders headers without token 1`] = `
12
+ Object {
13
+ "Accept": "application/json, text/plain, */*",
14
+ "Content-Type": "application/json",
15
+ }
16
+ `;
17
+
18
+ exports[`Communicator getMeta meta normal 1`] = `
19
+ Object {
20
+ "audit_source_type": "Backend",
21
+ "browser_page_resolution": "800x600",
22
+ "cookies_enabled": true,
23
+ "ip": "127.0.0.1",
24
+ "js_enabled": true,
25
+ "language": "ENG",
26
+ "user_agent": "_userAgent_",
27
+ }
28
+ `;
29
+
30
+ exports[`Communicator processingQueryParams queryParams multi 1`] = `"queryParamKey1=queryParamValue1&queryParamKey2=queryParamValue2"`;
31
+
32
+ exports[`Communicator processingQueryParams queryParams normal 1`] = `"queryParamKey1=queryParamValue1"`;
33
+
34
+ exports[`Communicator requests createSession 1`] = `
35
+ Object {
36
+ "headers": Object {
37
+ "Accept": "application/json, text/plain, */*",
38
+ "Authorization": "Bearer _authToken_",
39
+ "Content-Type": "application/json",
40
+ },
41
+ "method": "POST",
42
+ "url": "https://google.com/sign-in/session",
43
+ }
44
+ `;
45
+
46
+ exports[`Communicator requests emailUpdate 1`] = `
47
+ Object {
48
+ "body": "{\\"email\\":\\"test@test.com\\"}",
49
+ "headers": Object {
50
+ "Accept": "application/json, text/plain, */*",
51
+ "Authorization": "Bearer _authToken_",
52
+ "Content-Type": "application/json",
53
+ },
54
+ "method": "PATCH",
55
+ "url": "https://google.com/sign-in/email",
56
+ }
57
+ `;
58
+
59
+ exports[`Communicator requests getCurrentUserProfile 1`] = `
60
+ Object {
61
+ "headers": Object {
62
+ "Accept": "application/json, text/plain, */*",
63
+ "Authorization": "Bearer _accessToken_",
64
+ "Content-Type": "application/json",
65
+ },
66
+ "method": "GET",
67
+ "url": "https://google.com/user",
68
+ }
69
+ `;
70
+
71
+ exports[`Communicator requests registration 1`] = `
72
+ Object {
73
+ "body": "{\\"name\\":\\"_companyName_\\",\\"source\\":{\\"hash\\":\\"_hash_\\",\\"device_type\\":\\"mobile\\",\\"ga_id\\":\\"_gaId_\\",\\"origin\\":\\"_origin_\\"}}",
74
+ "headers": Object {
75
+ "Accept": "application/json, text/plain, */*",
76
+ "Authorization": "Bearer _accessToken_",
77
+ "Content-Type": "application/json",
78
+ },
79
+ "method": "POST",
80
+ "url": "https://google.com/clients/registration",
81
+ }
82
+ `;
83
+
84
+ exports[`Communicator requests setupChallenge 1`] = `
85
+ Object {
86
+ "headers": Object {
87
+ "Accept": "application/json, text/plain, */*",
88
+ "Authorization": "Bearer _authToken_",
89
+ "Content-Type": "application/json",
90
+ },
91
+ "method": "GET",
92
+ "queryParams": Object {
93
+ "type": "email_otp",
94
+ },
95
+ "url": "https://google.com/sign-in/challenge",
96
+ }
97
+ `;
98
+
99
+ exports[`Communicator requests signIn 1`] = `
100
+ Object {
101
+ "body": "{\\"captcha_response\\":\\"_\\",\\"meta\\":{\\"audit_source_type\\":\\"Backend\\",\\"browser_page_resolution\\":\\"800x600\\",\\"cookies_enabled\\":true,\\"ip\\":\\"127.0.0.1\\",\\"js_enabled\\":true,\\"language\\":\\"ENG\\",\\"user_agent\\":\\"_userAgent_\\"},\\"mobile\\":\\"+16234401486\\"}",
102
+ "headers": Object {
103
+ "Accept": "application/json, text/plain, */*",
104
+ "Content-Type": "application/json",
105
+ },
106
+ "method": "POST",
107
+ "url": "https://google.com/sign-in",
108
+ }
109
+ `;
110
+
111
+ exports[`Communicator requests signUp 1`] = `
112
+ Object {
113
+ "body": "{\\"locale\\":\\"en\\",\\"mobile\\":\\"+16234401486\\",\\"timezone_name\\":\\"Europe/Tallin\\"}",
114
+ "headers": Object {
115
+ "Accept": "application/json, text/plain, */*",
116
+ "Content-Type": "application/json",
117
+ },
118
+ "method": "POST",
119
+ "url": "https://google.com/sign-up",
120
+ }
121
+ `;
122
+
123
+ exports[`Communicator requests verifyChallenge 1`] = `
124
+ Object {
125
+ "body": "{\\"type\\":\\"email_otp\\",\\"value\\":\\"123456\\"}",
126
+ "headers": Object {
127
+ "Accept": "application/json, text/plain, */*",
128
+ "Authorization": "Bearer _authToken_",
129
+ "Content-Type": "application/json",
130
+ },
131
+ "method": "POST",
132
+ "url": "https://google.com/sign-in/challenge",
133
+ }
134
+ `;
@@ -0,0 +1,52 @@
1
+ import {AccountTracker} from "../src";
2
+ import {accountTrackerInitPropsNormal} from "./testunits/accountTracker/general";
3
+ import {emailVerifyEvents, phoneVerifyEvents, registrationSuccessEvents} from "./testunits/accountTracker/events";
4
+
5
+ const mockGtag = jest.fn().mockImplementation();
6
+ const mockLintrk = jest.fn().mockImplementation();
7
+ const accountTrackerInitProps = {
8
+ ...accountTrackerInitPropsNormal,
9
+ gtag: mockGtag,
10
+ lintrk: mockLintrk,
11
+ };
12
+ const accountTracker = new AccountTracker(accountTrackerInitProps);
13
+
14
+ describe('AccountTracker', () => {
15
+ afterEach(() => {
16
+ jest.clearAllMocks();
17
+ });
18
+
19
+ test('sendPhoneVerifyEvent', () => {
20
+ accountTracker.sendPhoneVerifyEvent();
21
+
22
+ expect(mockGtag.mock.calls[0][1]).toBe(phoneVerifyEvents.ga4.action);
23
+ expect(mockGtag.mock.calls[0][2]).toEqual(phoneVerifyEvents.ga4.event);
24
+ expect(mockGtag).toHaveBeenCalled();
25
+
26
+ expect(mockLintrk.mock.calls[0][0]).toBe(phoneVerifyEvents.linkedIn.action);
27
+ expect(mockLintrk.mock.calls[0][1]).toEqual(phoneVerifyEvents.linkedIn.event);
28
+ expect(mockLintrk).toHaveBeenCalled();
29
+ });
30
+
31
+ test('sendEmailVerifyEvent', () => {
32
+ accountTracker.sendEmailVerifyEvent();
33
+
34
+ expect(mockGtag.mock.calls[0][1]).toBe(emailVerifyEvents.ga4.action);
35
+ expect(mockGtag.mock.calls[0][2]).toEqual(emailVerifyEvents.ga4.event);
36
+ expect(mockGtag).toHaveBeenCalled();
37
+
38
+ expect(mockLintrk.mock.calls[0][0]).toBe(emailVerifyEvents.linkedIn.action);
39
+ expect(mockLintrk.mock.calls[0][1]).toEqual(emailVerifyEvents.linkedIn.event);
40
+ expect(mockLintrk).toHaveBeenCalled();
41
+ });
42
+
43
+ test('sendRegistrationSuccessEvent', () => {
44
+ accountTracker.sendRegistrationSuccessEvent();
45
+
46
+ expect(mockGtag).not.toHaveBeenCalled();
47
+
48
+ expect(mockLintrk.mock.calls[0][0]).toBe(registrationSuccessEvents.linkedIn.action);
49
+ expect(mockLintrk.mock.calls[0][1]).toEqual(registrationSuccessEvents.linkedIn.event);
50
+ expect(mockLintrk).toHaveBeenCalled();
51
+ });
52
+ });
@@ -0,0 +1,99 @@
1
+ import {Communicator} from "../src";
2
+ import {
3
+ headerTokenNormal,
4
+ queryParamsMulti,
5
+ queryParamsNormal
6
+ } from "./testunits/communicator/utils";
7
+ import {
8
+ createSessionData,
9
+ emailUpdateData,
10
+ getCurrentUserProfileData,
11
+ registrationData,
12
+ setupChallengeData,
13
+ signInData,
14
+ signUpData,
15
+ verifyChallengeData
16
+ } from "./testunits/communicator/requests";
17
+ import {communicatorTestData} from "./testunits/communicator/general";
18
+
19
+ const communicator = new Communicator(communicatorTestData.initProps);
20
+
21
+ describe('Communicator getHeaders', () => {
22
+ const getHeaders = communicator['getHeaders'];
23
+
24
+ test('headers without token', () => {
25
+ expect(getHeaders()).toMatchSnapshot();
26
+ });
27
+
28
+ test('headers with token', () => {
29
+ expect(getHeaders(headerTokenNormal)).toMatchSnapshot();
30
+ });
31
+ });
32
+
33
+ describe('Communicator getMeta', () => {
34
+ const getMeta = communicator['getMeta'];
35
+
36
+ test('meta normal', () => {
37
+ expect(getMeta(communicatorTestData.browserData)).toMatchSnapshot();
38
+ });
39
+ });
40
+
41
+ describe('Communicator processingQueryParams', () => {
42
+ const processingQueryParams = communicator['processingQueryParams'];
43
+
44
+ test('queryParams empty', () => {
45
+ expect(processingQueryParams({})).toEqual('');
46
+ });
47
+
48
+ test('queryParams normal', () => {
49
+ expect(processingQueryParams(queryParamsNormal)).toMatchSnapshot();
50
+ });
51
+
52
+ test('queryParams multi', () => {
53
+ expect(processingQueryParams(queryParamsMulti)).toMatchSnapshot();
54
+ });
55
+ });
56
+
57
+ describe('Communicator requests', () => {
58
+ jest.spyOn(Communicator.prototype as any, 'send').mockImplementation((value) => value);
59
+
60
+ test('signIn', async () => {
61
+ const signInRequestData = await communicator.signIn(signInData);
62
+ expect(signInRequestData).toMatchSnapshot();
63
+ });
64
+
65
+ test('signUp', async () => {
66
+ const signUpRequestData = await communicator.signUp(signUpData);
67
+ expect(signUpRequestData).toMatchSnapshot();
68
+ });
69
+
70
+ test('setupChallenge', async () => {
71
+ const setupChallengeRequestData = await communicator.setupChallenge(setupChallengeData);
72
+ expect(setupChallengeRequestData).toMatchSnapshot();
73
+ });
74
+
75
+ test('verifyChallenge', async () => {
76
+ const verifyChallengeRequestData = await communicator.verifyChallenge(verifyChallengeData);
77
+ expect(verifyChallengeRequestData).toMatchSnapshot();
78
+ });
79
+
80
+ test('emailUpdate', async () => {
81
+ const emailUpdateRequestData = await communicator.emailUpdate(emailUpdateData);
82
+ expect(emailUpdateRequestData).toMatchSnapshot();
83
+ });
84
+
85
+ test('createSession', async () => {
86
+ const createSessionRequestData = await communicator.createSession(createSessionData);
87
+ expect(createSessionRequestData).toMatchSnapshot();
88
+ });
89
+
90
+ test('getCurrentUserProfile', async () => {
91
+ const getCurrentUserProfileRequestData = await communicator.getCurrentUserProfile(getCurrentUserProfileData);
92
+ expect(getCurrentUserProfileRequestData).toMatchSnapshot();
93
+ });
94
+
95
+ test('registration', async () => {
96
+ const registrationRequestData = await communicator.registration(registrationData);
97
+ expect(registrationRequestData).toMatchSnapshot();
98
+ });
99
+ });
@@ -0,0 +1,50 @@
1
+ import {accountTrackerInitPropsNormal} from "./general";
2
+
3
+ const phoneVerifyEvents = {
4
+ ga4: {
5
+ action: 'verify_contact',
6
+ event: {
7
+ contact: 'phone',
8
+ origin: accountTrackerInitPropsNormal.origin,
9
+ send_to: accountTrackerInitPropsNormal.ga4Id,
10
+ },
11
+ },
12
+ linkedIn: {
13
+ action: 'track',
14
+ event: {
15
+ conversation_id: 8612332,
16
+ },
17
+ },
18
+ };
19
+
20
+ const emailVerifyEvents = {
21
+ ga4: {
22
+ action: 'verify_contact',
23
+ event: {
24
+ contact: 'email',
25
+ origin: accountTrackerInitPropsNormal.origin,
26
+ send_to: accountTrackerInitPropsNormal.ga4Id,
27
+ },
28
+ },
29
+ linkedIn: {
30
+ action: 'track',
31
+ event: {
32
+ conversation_id: 8612340,
33
+ },
34
+ },
35
+ };
36
+
37
+ const registrationSuccessEvents = {
38
+ linkedIn: {
39
+ action: 'track',
40
+ event: {
41
+ conversation_id: 8612308,
42
+ },
43
+ },
44
+ };
45
+
46
+ export {
47
+ phoneVerifyEvents,
48
+ emailVerifyEvents,
49
+ registrationSuccessEvents,
50
+ }
@@ -0,0 +1,8 @@
1
+ const accountTrackerInitPropsNormal = {
2
+ origin: '_origin_',
3
+ ga4Id: '_ga4Id_',
4
+ };
5
+
6
+ export {
7
+ accountTrackerInitPropsNormal,
8
+ }
@@ -0,0 +1,31 @@
1
+ import {TAccountBrowserData, TChallenge, TRegistrationRequestBodySourceDeviceType} from "../../../src/types";
2
+
3
+ const communicatorTestData = {
4
+ initProps: {
5
+ clientAuthApiBaseUrl: 'https://google.com/',
6
+ clientFAPIBaseUrl: 'https://google.com/',
7
+ },
8
+ browserData: {
9
+ innerWidth: 800,
10
+ innerHeight: 600,
11
+ isCookieEnabled: true,
12
+ userAgent: '_userAgent_',
13
+ } as TAccountBrowserData,
14
+ locale: 'en',
15
+ timezoneName: 'Europe/Tallin',
16
+ phoneNumber: '+16234401486',
17
+ email: 'test@test.com',
18
+ challenge: 'email_otp' as TChallenge,
19
+ companyName: '_companyName_',
20
+ deviceType: 'mobile' as TRegistrationRequestBodySourceDeviceType,
21
+ otpCode: '123456',
22
+ authToken: '_authToken_',
23
+ accessToken: '_accessToken_',
24
+ hash: '_hash_',
25
+ gaId: '_gaId_',
26
+ origin: '_origin_',
27
+ }
28
+
29
+ export {
30
+ communicatorTestData
31
+ }
@@ -0,0 +1,64 @@
1
+ import {
2
+ TCreateSessionRequestData,
3
+ TEmailUpdateRequestData, TGetCurrentUserProfileRequestData, TRegistrationRequestData,
4
+ TSetupChallengeRequestData,
5
+ TSignInByMobileRequestData,
6
+ TSignUpByMobileRequestData,
7
+ TVerifyChallengeRequestData
8
+ } from "../../../src/types";
9
+ import {communicatorTestData} from "./general";
10
+
11
+ const signInData: TSignInByMobileRequestData = {
12
+ phoneNumber: communicatorTestData.phoneNumber,
13
+ browserData: communicatorTestData.browserData,
14
+ };
15
+
16
+ const signUpData: TSignUpByMobileRequestData = {
17
+ locale: communicatorTestData.locale,
18
+ phoneNumber: communicatorTestData.phoneNumber,
19
+ timezoneName: communicatorTestData.timezoneName,
20
+ };
21
+
22
+ const setupChallengeData: TSetupChallengeRequestData = {
23
+ type: communicatorTestData.challenge,
24
+ authToken: communicatorTestData.authToken,
25
+ };
26
+
27
+ const verifyChallengeData: TVerifyChallengeRequestData = {
28
+ authToken: communicatorTestData.authToken,
29
+ type: communicatorTestData.challenge,
30
+ code: communicatorTestData.otpCode,
31
+ };
32
+
33
+ const emailUpdateData: TEmailUpdateRequestData = {
34
+ authToken: communicatorTestData.authToken,
35
+ email: communicatorTestData.email,
36
+ };
37
+
38
+ const createSessionData: TCreateSessionRequestData = {
39
+ authToken: communicatorTestData.authToken,
40
+ };
41
+
42
+ const getCurrentUserProfileData: TGetCurrentUserProfileRequestData = {
43
+ accessToken: communicatorTestData.accessToken,
44
+ };
45
+
46
+ const registrationData: TRegistrationRequestData = {
47
+ accessToken: communicatorTestData.accessToken,
48
+ name: communicatorTestData.companyName,
49
+ deviceType: communicatorTestData.deviceType,
50
+ hash: communicatorTestData.hash,
51
+ gaId: communicatorTestData.gaId,
52
+ origin: communicatorTestData.origin,
53
+ };
54
+
55
+ export {
56
+ signInData,
57
+ signUpData,
58
+ setupChallengeData,
59
+ verifyChallengeData,
60
+ emailUpdateData,
61
+ createSessionData,
62
+ getCurrentUserProfileData,
63
+ registrationData,
64
+ }
@@ -0,0 +1,14 @@
1
+ const headerTokenNormal = '_token_'
2
+ const queryParamsNormal = {
3
+ queryParamKey1: 'queryParamValue1',
4
+ }
5
+ const queryParamsMulti = {
6
+ queryParamKey1: 'queryParamValue1',
7
+ queryParamKey2: 'queryParamValue2',
8
+ }
9
+
10
+ export {
11
+ headerTokenNormal,
12
+ queryParamsNormal,
13
+ queryParamsMulti,
14
+ }
@@ -1,5 +0,0 @@
1
- // TODO: There should be unit tests
2
-
3
- test('modifyOrigin', () => {
4
- expect(true).toBe(true);
5
- });