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

Fixes #65: Submit online application to Prof M School #78

Merged
merged 4 commits into from
Jul 10, 2018

Conversation

lschaefer-sugarcrm
Copy link
Contributor

  • Add new fields for the application form
  • Update the Applicant record view layout
  • Create Online Application Form
  • Create page that is displayed when user submits application form
  • Update Postman Collection to create campaigns
  • Update Postman sample data to include application data
  • Add unit tests
  • Add acceptance tests
  • Add documentation

*
* @return \SugarQuery
*/
protected function getSugarQuery()
Copy link
Member

Choose a reason for hiding this comment

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

What's the motivation of this helper? It would seem to me like you'd want to build the SQL query in this method instead of in getOnlineApplicationCampaignId()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created this helper so that I would be able to mock the SugarQuery in automated tests. I followed a similar pattern in https://github.com/sugarcrm/school/blob/master/package/src/custom/modules/Contacts/Students_Gradebook.php.

Copy link
Member

Choose a reason for hiding this comment

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

Could we add a comment to PHPdoc that explains purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, updated

*
* @return null|\SugarBean
*/
protected function getNewCampaignBean()
Copy link
Member

Choose a reason for hiding this comment

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

Is this meant to be overridable? Is the idea we could support different types of SugarBeans?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same idea for this one. I broke out the Campaign bean so I could mock it in automated tests.

Copy link
Member

Choose a reason for hiding this comment

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

Same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, updated

$results = $q->execute();

if(sizeof($results) != 1 || !$results[0]['id']){
throw new \Exception("Unable to find ID for the Campaign named Online Applications");
Copy link
Member

Choose a reason for hiding this comment

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

Does this message get displayed to user? If so, we should consider using a language label.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question! I tried to find a way to display this message to the user, but I couldn't figure out how. No matter what I did, the page just displayed "We are sorry, the server is currently unavailable, please try again later." and the error message never displayed in the console. Is there a way to push a more informative message to the browser?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, you could echo a message/HTML here which should get displayed in browser. Throwing an exception will cause server to treat it like an HTTP error response. This exception message is likely only placed in php error log.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I played around with this some more. If I echo a message, it gets sent back as the Campaign ID, which isn't great. I decided to add some extra error handling to the Application Form to display an alert if the Campaign ID comes back empty (this would happen if someone installed Prof M without inserting the sample data).

Copy link
Member

@mmarum-sugarcrm mmarum-sugarcrm Jun 28, 2018

Choose a reason for hiding this comment

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

If you convert this to a REST API then you can throw a SugarApiException or extend SugarAPiExcpeiont to create your own. That'll return a JSON encoded error message that'll allow a consumer to do error handling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the exception and error handling.

- Add new fields for the application form
- Update the Applicant record view layout
- Create Online Application Form
- Create page that is displayed when user submits application form
- Update Postman Collection to create campaigns
- Update Postman sample data to include application data
- Add unit tests
- Add acceptance tests
- Add documentation
}
});
// Get the ID of the Online Applications Campaign
xhr.open("GET", urlBase + "/index.php?entryPoint=getOnlineApplicationsCampaign");
Copy link
Member

Choose a reason for hiding this comment

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

Why is this an entrypoint? This is simply returning a record ID. If it's meant to be machine consumable then it should be a REST API endpoint. You can make it a public endpoint which should allow it to be accessible without an OAuth token. It should be relatively straight forward to convert to a public rest API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the code to be an endpoint instead of an entrypoint. I've emailed @rhoggSugarcrm to see if I'm testing the endpoint in the best way.

Copy link
Contributor

Choose a reason for hiding this comment

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

I currently recommend using Thorn to test REST API endpoints, but it may be a bit of work to get it set up.

PHPUnit is certainly adequate until then.

Copy link
Member

@mmarum-sugarcrm mmarum-sugarcrm left a comment

Choose a reason for hiding this comment

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

One last nitpick.


}

?>
Copy link
Member

Choose a reason for hiding this comment

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

Remove pls. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

May I make a recommendation (as the guy who was pinged on a totally unrelated issue and is now butting in because he didn't unsubscribe 😝)?

If you add some sort of linting checks to .travis.yml hopefully PHP closing tags and similar would be caught automatically. IMHO that's a best practice anyhow 😸

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lol - feel free to butt in! We have #41 on the backlog.

Remove entrypoint code and add tests

Update Application Form to use REST endpoint

Update Exception type

Remove closing tag
@mmarum-sugarcrm mmarum-sugarcrm merged commit 2362a8f into master Jul 10, 2018
@lschaefer-sugarcrm lschaefer-sugarcrm deleted the issue-65 branch July 10, 2018 17:10
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.

3 participants