Skip to content

Commit

Permalink
fix: addressing pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
michelleinez committed Dec 18, 2024
1 parent 0cc6a18 commit dfbbc06
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 25 deletions.
56 changes: 33 additions & 23 deletions src/pages/LoanFinding/LoanFinding.vue
Original file line number Diff line number Diff line change
Expand Up @@ -199,30 +199,43 @@ export default {
apollo: {
preFetch(config, client) {
return client.query({
query: experimentAssignmentQuery, variables: { id: THREE_LOANS_RECOMMENDED_ROW_EXP_KEY }
}).then(async () => {
const loanRecommendationsExp = await client.query({
query: experimentAssignmentQuery,
variables: { id: THREE_LOANS_RECOMMENDED_ROW_EXP_KEY }
}).then(() => {
return client.query({
query: experimentAssignmentQuery,
variables: { id: LOAN_RECOMMENDATIONS_EXP_KEY }
});
}).then(loanRecommendationsExp => {
const useRecommendations = loanRecommendationsExp?.data?.experiment?.version === 'b';
const recommendedLoansPromise = client.query({
query: useRecommendations ? loanRecommendationsQueryExtended : flssLoansQueryExtended,
variables: useRecommendations ? {
...prefetchedRecommendationsVariables,
userId: config.userId || null
} : prefetchedFlssVariables
});
return Promise.all([
client.query({ query: userInfoQuery }),
client.query({ query: experimentAssignmentQuery, variables: { id: FIVE_DOLLARS_NOTES_EXP } }),
client.query({ query: experimentAssignmentQuery, variables: { id: FLSS_ONGOING_EXP_KEY } }),
recommendedLoansPromise
]);
return client.query({ query: userInfoQuery })
.then(userInfoResult => {
const userId = userInfoResult?.data?.my?.userAccount?.id || null;
const recommendedLoansPromise = client.query({
query: useRecommendations ? loanRecommendationsQueryExtended : flssLoansQueryExtended,
variables: useRecommendations ? {
...prefetchedRecommendationsVariables,
userId
} : prefetchedFlssVariables
});
return Promise.all([
Promise.resolve(userInfoResult),
client.query({
query: experimentAssignmentQuery,
variables: { id: FIVE_DOLLARS_NOTES_EXP }
}),
client.query({
query: experimentAssignmentQuery,
variables: { id: FLSS_ONGOING_EXP_KEY }
}),
recommendedLoansPromise
]);
});
});
},
}
},
computed: {
isLoggedIn() {
Expand Down Expand Up @@ -287,7 +300,7 @@ export default {
let loans = [];
if (this.enableLoanRecommendations) {
const response = await runRecommendationsQuery(this.apollo, {
userId: this.userInfo?.id,
userId: this.userInfo?.id || null,
origin: FLSS_ORIGIN_LEND_BY_CATEGORY,
limit: 12
});
Expand Down Expand Up @@ -485,10 +498,7 @@ export default {
} else {
const flssLoansData = this.apollo.readQuery({
query: flssLoansQueryExtended,
variables: {
pageLimit: 4,
origin: FLSS_ORIGIN_LEND_BY_CATEGORY
}
variables: prefetchedFlssVariables
});
cachedRecommendedLoans = flssLoansData?.fundraisingLoans?.values?.filter(loan => loan !== null) ?? [];
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/fixtures/mockLoanSearchData.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const mockState = {
partnerId: [1],
isMatchable: true,
flexibleFundraisingEnabled: false,
activityId: [9],
activityId: [9]
};

export const savedSearchParams = {
Expand Down
42 changes: 41 additions & 1 deletion test/unit/specs/util/loanSearch/dataUtils.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { runFacetsQueries, runLoansQuery, fetchLoanFacets } from '#src/util/loanSearch/dataUtils';
import {
runFacetsQueries,
runLoansQuery,
fetchLoanFacets,
runRecommendationsQuery
} from '#src/util/loanSearch/dataUtils';
import * as flssUtils from '#src/util/flssUtils';
import loanFacetsQuery from '#src/graphql/query/loanFacetsQuery.graphql';
import loanEnumsQuery from '#src/graphql/query/loanEnumsQuery.graphql';
Expand Down Expand Up @@ -128,6 +133,41 @@ describe('dataUtils.js', () => {
});
});

describe('runRecommendationsQuery', () => {
let spyFetchRecommendedLoans;
const apollo = {};
const loans = [{ test: 'test' }];
const totalCount = 5;
const origin = FLSS_ORIGIN_NOT_SPECIFIED;
const fakeUserId = 54321;
const limit = 12;
beforeEach(() => {
spyFetchRecommendedLoans = jest.spyOn(flssUtils, 'fetchRecommendedLoans')
.mockImplementation(() => Promise.resolve({ values: loans, totalCount }));
});

afterEach(jest.restoreAllMocks);

it('should return recommended loans', async () => {
const result = await runRecommendationsQuery(apollo, {
origin,
filterObject: null,
sortBy: 'personalized',
userId: fakeUserId,
limit
});
expect(spyFetchRecommendedLoans).toHaveBeenCalledWith(
apollo,
origin,
null,
'personalized',
fakeUserId,
limit
);
expect(result).toEqual({ loans, totalCount });
});
});

describe('fetchLoanFacets', () => {
const countryFacets = [{ country: { isoCode: 'a', name: 'Country' } }];
const sector = [{ id: 1, name: 'Test Sector' }];
Expand Down

0 comments on commit dfbbc06

Please sign in to comment.