Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ export class StreamClient<StreamFeedGenerics extends DefaultGenerics = DefaultGe
}

replaceReactionOptions = (options: {
rankingVars?: Record<string, string | number>;
rankingVars?: string | Record<string, string | number>;
reactionKindsFilter?: string[];
reactions?: Record<string, string | boolean | string[] | Record<string, string | number>>;
withOwnChildren?: boolean;
Expand All @@ -522,7 +522,15 @@ export class StreamClient<StreamFeedGenerics extends DefaultGenerics = DefaultGe
options.withRecentReactions = options.reactions.recent as boolean;
}
if (options.reactions.ranking_vars != null) {
options.rankingVars = options.reactions.ranking_vars as Record<string, string | number>;
if (typeof options.reactions.ranking_vars === 'object') {
options.rankingVars = options.reactions.ranking_vars as Record<string, string | number>;
} else if (typeof options.reactions.ranking_vars === 'string') {
options.rankingVars = options.reactions.ranking_vars as string;
}
}
// if ranking vars are Record, json stringify them
if (options.rankingVars && typeof options.rankingVars === 'object') {
options.rankingVars = JSON.stringify(options.rankingVars);
}
if (options.reactions.score_vars != null) {
options.withScoreVars = options.reactions.score_vars as boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type FeedPaginationOptions = {
export type RankedFeedOptions = {
offset?: number;
ranking?: string;
rankingVars?: Record<string, string | number>;
rankingVars?: string | Record<string, string | number>;
session?: string;
withScoreVars?: boolean;
};
Expand Down
30 changes: 30 additions & 0 deletions test/integration/cloud/reaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,36 @@ describe('Reaction pagination', () => {
});
});

describe('#withRankingVarsAsMap', () => {
ctx.requestShouldNotError(async () => {
ctx.response = await ctx.bob.feed('user', ctx.alice.userId).get({
reactions: { score_vars: true },
limit: 4,
offset: 2,
rankingVars: { popular: 1, music: 4 },
});
});
});
describe('#withRankingVarsShouldErr', () => {
ctx.requestShouldError(400, async () => {
ctx.response = await ctx.bob.feed('user', ctx.alice.userId).get({
reactions: { score_vars: true },
limit: 4,
offset: 2,
rankingVars: ['popular', 1],
});
});
});
describe('#withRankingVarsAsString', () => {
ctx.requestShouldNotError(async () => {
ctx.response = await ctx.bob.feed('user', ctx.alice.userId).get({
reactions: { score_vars: true },
limit: 4,
offset: 2,
rankingVars: '{"sports":1,"music":4}',
});
});
});
describe('When bob reads alice her feed with all enrichment enabled', () => {
ctx.requestShouldNotError(async () => {
ctx.response = await ctx.bob.feed('user', ctx.alice.userId).get({
Expand Down