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

kiva / ui / 19147367510

06 Nov 2025 07:26PM UTC coverage: 91.443% (+41.5%) from 49.902%
19147367510

push

github

emuvente
test: refactor category-row-arrows-visible-mixin test with runner method

3722 of 3979 branches covered (93.54%)

Branch coverage included in aggregate %.

18923 of 20785 relevant lines covered (91.04%)

78.6 hits per line

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

97.76
/src/util/optimizelyUserMetrics.js
1
import { gql } from 'graphql-tag';
1✔
2
import numeral from 'numeral';
1✔
3
import thanksPageQuery from '#src/graphql/query/thanksPage.graphql';
1✔
4
import logReadQueryError from '#src/util/logReadQueryError';
1✔
5

6
export const hasLentBeforeCookie = 'kvu_lb';
1✔
7
export const hasDepositBeforeCookie = 'kvu_db';
1✔
8

9
function setUserAttribute(key, value) {
10✔
10
        if (typeof window === 'undefined') {
10!
11
                return;
×
12
        }
×
13

14
        window.optimizely = window.optimizely || [];
10✔
15
        window.optimizely.push({
10✔
16
                type: 'user',
10✔
17
                attributes: {
10✔
18
                        [key]: value,
10✔
19
                },
10✔
20
        });
10✔
21
}
10✔
22

23
/**
1✔
24
 * Checks if user is checking out with a US Direct Loan.
1✔
25
 * @param {Boolean} hasUsLoan
1✔
26
 */
1✔
27
export function userUsLoanCheckout(hasUsLoan) {
1✔
28
        setUserAttribute('us_loan_checkout', hasUsLoan ? 'yes' : 'no');
2✔
29
}
2✔
30

31
/**
1✔
32
 * Checks if user has visted kiva before on the.
1✔
33
 * @param {Boolean} hasEverLoggedIn
1✔
34
 */
1✔
35
export function userHasEverLoggedInBefore(hasEverLoggedIn) {
1✔
36
        setUserAttribute('has_ever_logged_in_before', hasEverLoggedIn ? 'yes' : 'no');
2✔
37
}
2✔
38

39
/**
1✔
40
 * Checks if user has visted kiva before.
1✔
41
 * @param {Boolean} hasLentBefore
1✔
42
 */
1✔
43
export function userHasLentBefore(hasLentBefore) {
1✔
44
        setUserAttribute('has_lent_before', hasLentBefore ? 'yes' : 'no');
3✔
45
}
3✔
46

47
/**
1✔
48
 * Checks if user has deposited into their kiva account before.
1✔
49
 * @param {Boolean} hasDepositedBefore
1✔
50
 */
1✔
51
export function userHasDepositBefore(hasDepositedBefore) {
1✔
52
        setUserAttribute('has_deposited_before', hasDepositedBefore ? 'yes' : 'no');
3✔
53
}
3✔
54

55
export const optimizelyUserDataQuery = gql`query optimizelyUserDataQuery {
1✔
56
        my {
1✔
57
                id
1✔
58
                loans(limit:1) {
1✔
59
                                totalCount
1✔
60
                }
1✔
61
                transactions(limit:1, filter:{category:deposit}) {
1✔
62
                                totalCount
1✔
63
                }
1✔
64
        }
1✔
65
}`;
1✔
66

67
export async function setUserDataCookies(cookieStore, apolloClient) {
1✔
68
        if (!cookieStore.get(hasLentBeforeCookie) || !cookieStore.get(hasDepositBeforeCookie)) {
2✔
69
                const { data } = await apolloClient.query({
1✔
70
                        query: optimizelyUserDataQuery,
1✔
71
                });
1✔
72

73
                const hasLentBefore = data?.my?.loans?.totalCount > 0;
1✔
74
                const hasDepositBefore = data?.my?.transactions?.totalCount > 0;
1✔
75

76
                cookieStore.set(hasLentBeforeCookie, hasLentBefore, { path: '/' });
1✔
77
                cookieStore.set(hasDepositBeforeCookie, hasDepositBefore, { path: '/' });
1✔
78
        }
1✔
79
}
2✔
80

81
export function buildUserDataGlobal(currentRoute, cookieStore, apolloClient) {
1✔
82
        const transactionId = currentRoute.query?.kiva_transaction_id
5✔
83
                ? numeral(currentRoute.query?.kiva_transaction_id).value()
5✔
84
                : null;
5✔
85

86
        if (!transactionId) {
5✔
87
                return null;
1✔
88
        }
1✔
89

90
        let data = null;
4✔
91
        try {
4✔
92
                data = apolloClient.readQuery({
4✔
93
                        query: thanksPageQuery,
4✔
94
                        variables: {
4✔
95
                                checkoutId: transactionId,
4✔
96
                                visitorId: cookieStore.get('uiv') || null,
5✔
97
                        }
5✔
98
                });
5✔
99
        } catch (e) {
5✔
100
                logReadQueryError(e, `Thanks page on server-entry failed: (transaction_id: ${transactionId})`);
1✔
101
        }
1✔
102

103
        const loans = data?.shop?.receipt?.items?.values
5✔
104
                .filter(item => item.basketItemType === 'loan_reservation')
5✔
105
                .map(item => item.loan) ?? [];
5✔
106

107
        return {
5✔
108
                viewer: {
5✔
109
                        userId: data?.my?.userAccount?.id,
5✔
110
                        displayName: `${data?.my?.userAccount?.firstName} ${data?.my?.userAccount?.lastName}`,
5✔
111
                        publicProfile: data?.my?.userAccount?.public
5✔
112
                },
5✔
113
                loans
5✔
114
        };
5✔
115
}
5✔
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

© 2025 Coveralls, Inc