Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: leaderboard should work with doubles instead of floats #1105

Merged
merged 5 commits into from
Jan 18, 2024
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
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ jobs:
node -v
./scripts/test-vector-packages.sh

- name: Run leaderboard tests for packages
run: |
node -v
./scripts/test-leaderboard-packages.sh

test-examples:
strategy:
matrix:
Expand Down
10 changes: 6 additions & 4 deletions packages/client-sdk-nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/client-sdk-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"integration-test-auth": "jest auth-client.test.ts --maxWorkers 1",
"integration-test-vector": "jest vector-control-plane.test.ts vector-data-plane.test.ts --maxWorkers 1",
"unit-test": "jest unit",
"integration-test": "jest integration --testPathIgnorePatterns \"auth-client.test.ts|vector-control-plane.test.ts|vector-data-plane.test.ts\" --maxWorkers 1",
"integration-test-leaderboard": "jest leaderboard --maxWorkers 1",
"integration-test": "jest integration --testPathIgnorePatterns \"auth-client.test.ts|vector-control-plane.test.ts|vector-data-plane.test.ts|leaderboard.test.ts\" --maxWorkers 1",
anitarua marked this conversation as resolved.
Show resolved Hide resolved
"build-deps": "cd ../core && npm run build && cd - && cd ../common-integration-tests && npm run build && cd -",
"build-and-run-tests": "npm run build-deps && jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1",
"lint": "eslint . --ext .ts",
Expand Down Expand Up @@ -51,7 +52,7 @@
"uuid": "8.3.2"
},
"dependencies": {
"@gomomento/generated-types": "0.97.1",
"@gomomento/generated-types": "0.102.0",
"@gomomento/sdk-core": "file:../core",
"@grpc/grpc-js": "1.9.0",
"@types/google-protobuf": "3.15.10",
Expand Down
8 changes: 4 additions & 4 deletions packages/client-sdk-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions packages/client-sdk-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"unit-test": "jest unit",
"integration-test-auth": "jest --env=jsdom auth-client.test.ts --maxWorkers 1",
"integration-test-vector": "jest vector-control-plane.test.ts vector-data-plane.test.ts --maxWorkers 1",
"integration-test-jsdom": "jest integration --env=jsdom --testMatch \"**/dictionary.test.ts|**/ping.test.ts|*/topic-client.test.ts\" --maxWorkers 1",
"integration-test-happy-dom": "jest integration --env=@happy-dom/jest-environment --testPathIgnorePatterns \"dictionary.test.ts|ping.test.ts|topic-client.test.ts|auth-client.test.ts|vector-control-plane.test.ts|vector-data-plane.test.ts\" --maxWorkers 1",
"integration-test-leaderboard": "jest --env=jsdom leaderboard --maxWorkers 1",
"integration-test-jsdom": "jest integration --env=jsdom --testMatch \"**/dictionary.test.ts|**/ping.test.ts|*/topic-client.test.ts|leaderboard.test.ts\" --maxWorkers 1",
"integration-test-happy-dom": "jest integration --env=@happy-dom/jest-environment --testPathIgnorePatterns \"dictionary.test.ts|ping.test.ts|topic-client.test.ts|auth-client.test.ts|vector-control-plane.test.ts|vector-data-plane.test.ts|leaderboard.test.ts\" --maxWorkers 1",
"integration-test": "npm run integration-test-happy-dom && npm run integration-test-jsdom",
"build-deps": "cd ../core && npm run build && cd - && cd ../common-integration-tests && npm run build && cd -",
"build-and-run-tests": "npm run build-deps && jest --testPathIgnorePatterns auth-client.test.ts --maxWorkers 1",
Expand Down Expand Up @@ -55,7 +56,7 @@
"xhr2": "0.2.1"
},
"dependencies": {
"@gomomento/generated-types-webtext": "0.97.1",
"@gomomento/generated-types-webtext": "0.102.0",
"@gomomento/sdk-core": "file:../core",
"@types/google-protobuf": "3.15.6",
"google-protobuf": "3.21.2",
Expand Down
51 changes: 51 additions & 0 deletions packages/common-integration-tests/src/leaderboard-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,4 +1017,55 @@ export function runLeaderboardClientTests(
);
});
});

describe('Leaderboard should be able to upsert and fetch double precision floats', () => {
const leaderboardName = `test-leaderboard-${v4()}`;

const upsertsAndFetchesDoubles = async (leaderboard: ILeaderboard) => {
const elements = new Map([
[123, 27.004309862363737],
[456, 16777217],
[789, 300.5],
]);

const response = await leaderboard.upsert(elements);
expectWithMessage(() => {
expect(response).toBeInstanceOf(LeaderboardUpsert.Success);
}, `expected Success but got ${response.toString()}`);

const fetchResponse = await leaderboard.fetchByScore();
expectWithMessage(() => {
expect(fetchResponse).toBeInstanceOf(LeaderboardFetch.Success);
}, `expected Found but got ${fetchResponse.toString()}`);
const receivedElements = (
fetchResponse as LeaderboardFetch.Success
).values();
const expectedElements = [
{
id: 123,
score: 27.004309862363737,
rank: 0,
},
{
id: 789,
score: 300.5,
rank: 1,
},
{
id: 456,
score: 16777217,
rank: 2,
},
];
expect(receivedElements).toEqual(expectedElements);
};
it('upserts and fetches doubles with correct precision', async () => {
await withTemporaryLeaderboard(
leaderboardClient,
leaderboardName,
integrationTestCacheName,
upsertsAndFetchesDoubles
);
});
});
}
16 changes: 16 additions & 0 deletions scripts/test-leaderboard-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -x
set -e

ROOT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )"/.. &> /dev/null && pwd )

echo "running leaderboard tests"

pushd ${ROOT_DIR}/packages/client-sdk-web
npm run integration-test-leaderboard
popd

pushd ${ROOT_DIR}/packages/client-sdk-nodejs
npm run integration-test-leaderboard
popd
Loading