Skip to content

Commit

Permalink
Add whitespace to filter string and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
benvinegar committed Dec 14, 2024
1 parent 9c49ed1 commit fecefc6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions app/analytics/__tests__/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,30 @@ describe("AnalyticsEngineAPI", () => {
},
});
});

test("should handle case where there are no results", async () => {
fetch
.mockResolvedValueOnce(
createFetchResponse({
data: [], // no visitor count results
}),
)
.mockResolvedValueOnce(
createFetchResponse({
data: [], // no non-visitor results
}),
);

const result = await api.getAllCountsByColumn(
"example.com",
"path",
"DAY",
"America/New_York",
);

expect(result).toEqual({});
expect(fetch).toHaveBeenCalledTimes(2);
});
});

describe("getEarliestEvents", () => {
Expand Down
4 changes: 3 additions & 1 deletion app/analytics/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,11 @@ export class AnalyticsEngineAPI {

let filterStr = filtersToSql(filters);
const _column = ColumnMappings[column];

if (keys.length > 0) {
filterStr += `AND ${_column} IN (${keys.map((key) => `'${key}'`).join(", ")})`;
filterStr += ` AND ${_column} IN (${keys.map((key) => `'${key}'`).join(", ")})`;
}

const query = `
SELECT ${_column},
${ColumnMappings.newVisitor} as isVisitor,
Expand Down

0 comments on commit fecefc6

Please sign in to comment.