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

Get user post ranks and top ranked whys#208 #263

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Chenxuan-Liu
Copy link

No description provided.

Copy link
Contributor

@ddfridley ddfridley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full credit for the code working, but I just can't tell from the test file if it's doing the right thing. I want to ask for using a different pattern (see the comments) to make it more visible what's coming out of the api calls. And some other clean up comments.

Thanks for seeing this last one through!

const uri = memoryServer.getUri();
await Mongo.connect(uri);
db = Mongo.db;
Rankings.setCollectionProps();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling .setCollectionProps is not needed for these models. It's done when the model is loaded.

test('5 have 2 why mosts, 2 have why leasts, 1 has 1 why most, 1 has 1 why least – nothing ranked', async () => {
const ids = Array.from({ length: 10 }, () => new ObjectId().toString());

await db.collection('points').insertMany([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works, but it would be shorter and clearer to say Points.insertMany

expect(console.error).toHaveBeenCalledWith(expect.stringMatching(/no user logged in/));
});

test('10 points in ids, nothing ranked', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making new ids here, every time the test is run, generate 10 (use console.info) and then copy them into an array here.

I'm learning that in the expect statements, what's expected needs to be more visible, meaning .objectToMatch({...}) so that when we look at the code in the test we can see what's expected. -- We are missing things by not looking at it.


expect(callback).toHaveBeenCalledWith({
ranks: [],
whys: expect.any(Array),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of .any use expect(callback.mock.calls[0][0]).toMatchObject([]) and it will through the error and then the error message text can be used to create the object to expect.

But this will only work if the ids are the same every time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

api getUserPostRanksAndTopRankedWhys(discussionId, round, ids, cb{ranks:[rank,...],whys: [point,...]}
2 participants