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

Projects: string to symbol for fetching published projects #26133

Merged
merged 1 commit into from
Nov 19, 2018

Conversation

Erin007
Copy link
Contributor

@Erin007 Erin007 commented Nov 16, 2018

As part of the ongoing investigation into an issue where only a limited number of Dance Party projects are displaying in the public gallery, I found and fixed a potentially related bug.

Calls to api/v1/projects/gallery/public/all/100 were returning projects of all types as expected; however calls to the api with specific project groups for example, api/v1/projects/gallery/public/events/100 or api/v1/projects/gallery/public/dance/100, were unexpectedly returning empty arrays even when there were projects of types in the specified group in the database.

BEFORE:
fetch-by-project-type-before

The problem occurred because the api route with a specific project group param, calls fetch_published_projects, which in turn calls fetch_published_project_types, which expects the project group to be a symbol, not a string. The project group needs to be a symbol because it is used to key into the PUBLISHED_PROJECT_TYPE_GROUPS hash.

AFTER:

fetch-by-project-type

Copy link
Contributor

@islemaster islemaster left a comment

Choose a reason for hiding this comment

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

🎉 Good find!

Regression test? This sort of issue suggests we're either missing tests, or our tests don't reflect how we're really using the API.

@Erin007
Copy link
Contributor Author

Erin007 commented Nov 16, 2018

@islemaster In this case, it looks like since we stub the response from the Pegasus database,

PEGASUS_DB.stubs(:[]).returns(db_result(stub_projects)).then.returns(db_result([]))
, our tests don't actually call fetch_published_project_types so they never have to key into PUBLISHED_PROJECT_TYPE_GROUPS. I'm not sure how to add a regression test for this specifically.

@davidsbailey
Copy link
Member

@islemaster I agree that adding a regression test is a good idea in principle but it seems like a poor bang-for-the-buck in this situation. Let me explain:

We already have this regression test, validating that a "bogus" project type can't be passed in:

test_user_gets_response_for(
:index,
name: 'bad request when project type is invalid',
params: -> {{project_type: 'bogus', limit: 1}},
response: :bad_request,

We also have this test, which is testing the right input, but doesn't catch it because we stub out the DB response:

test 'project details are correct listing published applab projects' do
Rails.stubs(:env).returns(ActiveSupport::StringInquirer.new('production'))
get :index, params: {project_type: 'applab', limit: 1}

I would say that we have relatively high code coverage by unit tests here without a clear path to getting it to the 100% mark.

A UI test to catch this would load "more" applab projects and then scroll to the bottom of the screen. this would require creating 100+ projects during a UI test (or stubbing out the limit value passed by the client), which is not ideal.

A UI test could load the url like https://studio.code.org/api/v1/projects/gallery/public/applab/100 , as part of the UI test that publishes/features 1 project, and ensure that something shows up. that seems a bit hacky though.

Please let me know if you see a better way to regression test this feature.

@Erin007 Erin007 changed the base branch from staging-next to staging November 16, 2018 22:42
Copy link
Contributor

@islemaster islemaster left a comment

Choose a reason for hiding this comment

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

Understood. Thanks!

@Erin007 Erin007 merged commit 5ec3bd5 into staging Nov 19, 2018
@Erin007 Erin007 deleted the dance-public-gallery branch November 19, 2018 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants