• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thoughtspot / visual-embed-sdk / #1941

06 Jun 2025 02:56PM UTC coverage: 93.271% (-0.6%) from 93.827%
#1941

Pull #215

yinstardev
test cov
Pull Request #215: SCAL-256749 present-event

1106 of 1270 branches covered (87.09%)

Branch coverage included in aggregate %.

39 of 45 new or added lines in 3 files covered. (86.67%)

9 existing lines in 2 files now uncovered.

2664 of 2772 relevant lines covered (96.1%)

66.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.68
/src/utils/processData.ts
1
import { getEmbedConfig } from '../embed/embedConfig';
15✔
2
import {
15✔
3
    disableAutoLogin,
4
    notifyAuthFailure,
5
    notifyAuthSuccess,
6
    notifyLogout,
7
} from '../embed/base';
8
import { AuthFailureType } from '../auth';
15✔
9
import { AuthType, CustomActionPayload, EmbedEvent } from '../types';
15✔
10
import { AnswerService } from './graphql/answerService/answerService';
15✔
11
import { resetCachedAuthToken } from '../authToken';
15✔
12
import { ERROR_MESSAGE } from '../errors';
15✔
13
import { logger } from '../utils/logger';
15✔
14
import { handleExitPresentMode } from '../utils';
15✔
15

16
/**
17
 * Process the ExitPresentMode event and handle default fullscreen exit
18
 * @param e - The event data
19
 */
20
function processExitPresentMode(e: any) {
NEW
21
    handleExitPresentMode();
×
NEW
22
    return e;
×
23
}
UNCOV
24

×
UNCOV
25
/**
×
26
 *
UNCOV
27
 * @param e
×
28
 * @param thoughtSpotHost
29
 */
30
export function processCustomAction(e: any, thoughtSpotHost: string) {
31
    const { session, embedAnswerData, contextMenuPoints } = e.data as CustomActionPayload;
32
    const answerService = new AnswerService(
33
        session,
34
        embedAnswerData || {},
35
        thoughtSpotHost,
36
        contextMenuPoints?.selectedPoints,
15✔
37
    );
6✔
38
    return {
6✔
39
        ...e,
40
        answerService,
12✔
41
    };
42
}
18✔
43

44
/**
6✔
45
 * Responds to AuthInit sent from host signifying successful authentication in host.
46
 * @param e
47
 * @returns {any}
48
 */
49
function processAuthInit(e: any) {
50
    notifyAuthSuccess();
51

52
    // Expose only allowed details (eg: userGUID) back to SDK users.
53
    return {
54
        ...e,
55
        data: {
56
            userGUID: e.data?.userGUID || e.payload?.userGUID,
2✔
57
        },
58
    };
59
}
2✔
60

61
/**
62
 *
8!
63
 * @param e
64
 * @param containerEl
65
 */
66
function processNoCookieAccess(e: any, containerEl: Element) {
67
    const {
68
        loginFailedMessage,
69
        suppressNoCookieAccessAlert,
70
        ignoreNoCookieAccess,
71
        suppressErrorAlerts,
72
    } = getEmbedConfig();
73
    if (!ignoreNoCookieAccess) {
74
        if (!suppressNoCookieAccessAlert && !suppressErrorAlerts) {
75
            // eslint-disable-next-line no-alert
76
            alert(ERROR_MESSAGE.THIRD_PARTY_COOKIE_BLOCKED_ALERT);
77
        }
78
        // eslint-disable-next-line no-param-reassign
6✔
79
        containerEl.innerHTML = loginFailedMessage;
6✔
80
    }
3✔
81
    notifyAuthFailure(AuthFailureType.NO_COOKIE_ACCESS);
82
    return e;
2✔
83
}
84

85
/**
3✔
86
 *
87
 * @param e
6✔
88
 * @param containerEl
6✔
89
 */
90
export function processAuthFailure(e: any, containerEl: Element) {
91
    const {
92
        loginFailedMessage, authType, disableLoginFailurePage, autoLogin,
93
    } = getEmbedConfig();
94
    
95
    const isEmbeddedSSO = authType === AuthType.EmbeddedSSO;
96
    const isTrustedAuth = authType === AuthType.TrustedAuthToken || authType === AuthType.TrustedAuthTokenCookieless;
15✔
97
    const isEmbeddedSSOInfoFailure = isEmbeddedSSO && e?.data?.type === AuthFailureType.UNAUTHENTICATED_FAILURE;
98
    if (autoLogin && isTrustedAuth) {
99
        // eslint-disable-next-line no-param-reassign
10✔
100
        containerEl.innerHTML = loginFailedMessage;
101
        notifyAuthFailure(AuthFailureType.IDLE_SESSION_TIMEOUT);
10✔
102
    } else if (authType !== AuthType.None && !disableLoginFailurePage && !isEmbeddedSSOInfoFailure) {
10✔
103
        // eslint-disable-next-line no-param-reassign
10!
104
        containerEl.innerHTML = loginFailedMessage;
10✔
105
        notifyAuthFailure(AuthFailureType.OTHER);
106
    }
3✔
107
    resetCachedAuthToken();
3✔
108
    return e;
7✔
109
}
110

5✔
111
/**
5✔
112
 *
113
 * @param e
10✔
114
 * @param containerEl
10✔
115
 */
116
function processAuthLogout(e: any, containerEl: Element) {
117
    const { loginFailedMessage } = getEmbedConfig();
118
    // eslint-disable-next-line no-param-reassign
119
    containerEl.innerHTML = loginFailedMessage;
120
    resetCachedAuthToken();
121
    disableAutoLogin();
122
    notifyLogout();
123
    return e;
1✔
124
}
125

1✔
126
/**
1✔
127
 *
1✔
128
 * @param type
1✔
129
 * @param e
1✔
130
 * @param thoughtSpotHost
131
 * @param containerEl
132
 */
133
export function processEventData(
134
    type: EmbedEvent,
135
    e: any,
136
    thoughtSpotHost: string,
137
    containerEl: Element,
138
): any {
139
    switch (type) {
15✔
140
        case EmbedEvent.CustomAction:
141
            return processCustomAction(e, thoughtSpotHost);
142
        case EmbedEvent.AuthInit:
143
            return processAuthInit(e);
144
        case EmbedEvent.NoCookieAccess:
145
            return processNoCookieAccess(e, containerEl);
67!
146
        case EmbedEvent.AuthFailure:
147
            return processAuthFailure(e, containerEl);
6✔
148
        case EmbedEvent.AuthLogout:
149
            return processAuthLogout(e, containerEl);
2✔
150
        case EmbedEvent.ExitPresentMode:
151
            return processExitPresentMode(e);
6✔
152
        default:
153
    }
5✔
154
    return e;
155
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc