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

kiva / ui / 14911871966

08 May 2025 04:57PM UTC coverage: 49.059% (+0.09%) from 48.969%
14911871966

push

github

emuvente
fix: provide current route ref value from server entry and remove contentful cookie

1595 of 3417 branches covered (46.68%)

Branch coverage included in aggregate %.

0 of 11 new or added lines in 5 files covered. (0.0%)

3 existing lines in 2 files now uncovered.

2393 of 4712 relevant lines covered (50.79%)

286.39 hits per line

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

27.03
/src/util/optimizelyUserMetrics.js
1
import numeral from 'numeral';
2
import thanksPageQuery from '#src/graphql/query/thanksPage.graphql';
3
import logReadQueryError from '#src/util/logReadQueryError';
4

5
function setUserAttribute(key, value) {
6
        if (typeof window === 'undefined') {
2!
7
                return;
×
8
        }
9

10
        window.optimizely = window.optimizely || [];
2✔
11
        window.optimizely.push({
2✔
12
                type: 'user',
13
                attributes: {
14
                        [key]: value,
15
                },
16
        });
17
}
18

19
/**
20
 * Checks if user is checking out with a US Direct Loan.
21
 * @param {Boolean} hasUsLoan
22
 */
23
export function userUsLoanCheckout(hasUsLoan) {
24
        setUserAttribute('us_loan_checkout', hasUsLoan ? 'yes' : 'no');
×
25
}
26

27
/**
28
 * Checks if user has visted kiva before on the.
29
 * @param {Boolean} hasEverLoggedIn
30
 */
31
export function userHasEverLoggedInBefore(hasEverLoggedIn) {
32
        setUserAttribute('has_ever_logged_in_before', hasEverLoggedIn ? 'yes' : 'no');
×
33
}
34

35
/**
36
 * Checks if user has visted kiva before.
37
 * @param {Boolean} hasLentBefore
38
 */
39
export function userHasLentBefore(hasLentBefore) {
40
        setUserAttribute('has_lent_before', hasLentBefore ? 'yes' : 'no');
1!
41
}
42

43
/**
44
 * Checks if user has deposited into their kiva account before.
45
 * @param {Boolean} hasDepositedBefore
46
 */
47
export function userHasDepositBefore(hasDepositedBefore) {
48
        setUserAttribute('has_deposited_before', hasDepositedBefore ? 'yes' : 'no');
1!
49
}
50

51
export function buildUserDataGlobal(currentRoute, cookieStore, apolloClient) {
52
        let data = null;
×
NEW
53
        const transactionId = currentRoute.query?.kiva_transaction_id
×
54
                ? numeral(currentRoute.query?.kiva_transaction_id).value()
55
                : null;
56
        try {
×
57
                data = transactionId ? apolloClient.readQuery({
×
58
                        query: thanksPageQuery,
59
                        variables: {
60
                                checkoutId: transactionId,
61
                                visitorId: cookieStore.get('uiv') || null,
×
62
                        }
63
                }) : {};
64
        } catch (e) {
65
                logReadQueryError(e, `Thanks page on server-entry failed: (transaction_id: ${transactionId})`);
×
66
        }
67

68
        const loans = data?.shop?.receipt?.items?.values
×
69
                .filter(item => item.basketItemType === 'loan_reservation')
×
70
                .map(item => item.loan) ?? [];
×
71

72
        return {
×
73
                viewer: {
74
                        userId: data?.my?.userAccount?.id,
75
                        displayName: `${data?.my?.userAccount?.firstName} ${data?.my?.userAccount?.lastName}`,
76
                        publicProfile: data?.my?.userAccount?.public
77
                },
78
                loans
79
        };
80
}
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