• 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

96.1
/src/util/loanChannelUtils.js
1
import {
1✔
2
        fetchLoanChannel,
3
        getCachedLoanChannel,
4
        getLoanChannelVariables,
5
        watchLoanChannel
6
} from '#src/util/flssUtils';
7
import loanChannelQuery from '#src/graphql/query/loanChannelDataExpanded.graphql';
1✔
8
import logReadQueryError from '#src/util/logReadQueryError';
1✔
9
import logFormatter from '#src/util/logFormatter';
1✔
10

11
/**
1✔
12
 * Returns the FLSS loan search state object based on the map and category
1✔
13
 *
1✔
14
 * @param {Array} queryMap The map mixin from loan-channel-query-map.js
1✔
15
 * @param {string} category The category from $route.params.category
1✔
16
 * @returns {Object} The loan search state object
1✔
17
 */
1✔
18
export function getFLSSQueryMap(queryMap, category) {
1✔
19
        const result = queryMap.find(c => c.url === category)?.flssLoanSearch;
18✔
20

21
        if (!result) {
18✔
22
                logFormatter(`The following category was not found in the FLSS query map: ${category}`, 'info');
9✔
23
        }
9✔
24

25
        return result;
18✔
26
}
18✔
27

28
/**
1✔
29
 * Transforms the FLSS channel data to match the lend channel data format
1✔
30
 *
1✔
31
 * @param {Object} data The data from FLSS
1✔
32
 * @returns {Object} The transformed channel data
1✔
33
 */
1✔
34
export function transformFLSSData(data) {
1✔
35
        return {
9✔
36
                shop: data?.shop ?? {},
9✔
37
                lend: { loanChannelsById: [{ ...data?.lend?.loanChannelsById?.[0], loans: data?.fundraisingLoans ?? {} }] }
9✔
38
        };
9✔
39
}
9✔
40

41
/**
1✔
42
 * Used to pre-fetch the loan channel data in the control component
1✔
43
 *
1✔
44
 * @param {Object} apollo The Apollo client instance
1✔
45
 * @param {Array} queryMap The map mixin from loan-channel-query-map.js
1✔
46
 * @param {string} channelUrl The URL of the loan channel
1✔
47
 * @param {Object} loanQueryVars The loan channel query variables
1✔
48
 */
1✔
49
export async function preFetchChannel(apollo, queryMap, channelUrl, loanQueryVars) {
1✔
50
        const queryMapFLSS = getFLSSQueryMap(queryMap, channelUrl);
4✔
51

52
        if (queryMapFLSS) {
4✔
53
                const filterObj = { ...queryMapFLSS };
2✔
54
                return fetchLoanChannel(apollo, filterObj, loanQueryVars);
2✔
55
        }
2✔
56

57
        try {
2✔
58
                return apollo.query({
2✔
59
                        query: loanChannelQuery,
2✔
60
                        variables: loanQueryVars
2✔
61
                });
2✔
62
        } catch (e) {
4!
63
                logReadQueryError(e, 'loanChannelUtils preFetchChannel loanChannelQuery');
×
64
        }
×
65
}
4✔
66

67
/**
1✔
68
 * Gets the loan channel data from the Apollo cache
1✔
69
 *
1✔
70
 * @param {Object} apollo The Apollo client instance
1✔
71
 * @param {Array} queryMap The map mixin from loan-channel-query-map.js
1✔
72
 * @param {string} channelUrl The URL of the loan channel
1✔
73
 * @param {Object} loanQueryVars The loan channel query variables
1✔
74
 * @returns {Object} The loan channel data
1✔
75
 */
1✔
76
export function getCachedChannel(apollo, queryMap, channelUrl, loanQueryVars) {
1✔
77
        const queryMapFLSS = getFLSSQueryMap(queryMap, channelUrl);
4✔
78

79
        if (queryMapFLSS) {
4✔
80
                return transformFLSSData(getCachedLoanChannel(apollo, queryMapFLSS, loanQueryVars));
2✔
81
        }
2✔
82

83
        try {
2✔
84
                return apollo.readQuery({ query: loanChannelQuery, variables: loanQueryVars });
2✔
85
        } catch (e) {
4✔
86
                logReadQueryError(e, 'loanChannelUtils getCachedChannel loanChannelQuery');
1✔
87
        }
1✔
88
}
4✔
89

90
/**
1✔
91
 * Gets the loan channel data from the API
1✔
92
 *
1✔
93
 * @param {Object} apollo The Apollo client instance
1✔
94
 * @param {Array} queryMap The map mixin from loan-channel-query-map.js
1✔
95
 * @param {string} channelUrl The URL of the loan channel
1✔
96
 * @param {Object} loanQueryVars The loan channel query variables
1✔
97
 * @param {Object} filterOverrides Filters that override or extend the query map filters (only for FLSS)
1✔
98
 * @returns {Object} The loan channel data, transformed if FLSS
1✔
99
 */
1✔
100
export async function getLoanChannel(apollo, queryMap, channelUrl, loanQueryVars, filterOverrides = {}) {
1✔
101
        const queryMapFLSS = getFLSSQueryMap(queryMap, channelUrl);
4✔
102

103
        if (queryMapFLSS) {
4✔
104
                const data = await fetchLoanChannel(apollo, { ...queryMapFLSS, ...filterOverrides }, loanQueryVars);
2✔
105
                return transformFLSSData(data);
2✔
106
        }
2✔
107

108
        try {
2✔
109
                return apollo.query({ query: loanChannelQuery, variables: loanQueryVars });
2✔
110
        } catch (e) {
4!
111
                logReadQueryError(e, 'loanChannelUtils getLoanChannel loanChannelQuery');
×
112
        }
×
113
}
4✔
114

115
/**
1✔
116
 * Watches the loan channel query and returns the observer
1✔
117
 *
1✔
118
 * @param {Object} apollo The Apollo client instance
1✔
119
 * @param {Array} queryMap The map mixin from loan-channel-query-map.js
1✔
120
 * @param {string} channelUrl The URL of the loan channel
1✔
121
 * @param {Object} loanQueryVars The loan channel query variables
1✔
122
 * @param {function} next The function to call in the observer subscription next callback
1✔
123
 * @param {function} watch The function to call to setup the component watch
1✔
124
 * @returns {Object} The Apollo watch observer
1✔
125
 */
1✔
126
export function watchChannelQuery(apollo, queryMap, channelUrl, loanQueryVars, next, watch) {
1✔
127
        const queryMapFLSS = getFLSSQueryMap(queryMap, channelUrl);
4✔
128
        // Check if current user should see the FLSS experiment
4✔
129
        const observer = queryMapFLSS
4✔
130
                ? watchLoanChannel(apollo, queryMapFLSS, loanQueryVars)
4✔
131
                : apollo.watchQuery({ query: loanChannelQuery, variables: loanQueryVars });
4✔
132

133
        if (observer) {
4✔
134
                observer.subscribe({
3✔
135
                        next: ({ data, loading }) => {
3✔
136
                                next(queryMapFLSS ? transformFLSSData(data) : data, loading);
3✔
137
                        }
3✔
138
                });
3✔
139

140
                watch(vars => {
3✔
141
                        observer.setVariables(queryMapFLSS ? getLoanChannelVariables(queryMapFLSS, vars) : vars);
3✔
142
                });
3✔
143

144
                return observer;
3✔
145
        }
3✔
146
}
4✔
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