OSD600 - Telescope - Testing for feed URLs

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • telescope

    A tool for tracking blogs in orbit around Seneca's open source involvement (by Seneca-CDOT)

  • Another thing from the review was that allowing a feed URL could break the back end as it would now store a feed URL as a blog URL. So, I investigated this and thanks to some helpful information from alexsam29, I found that the blog URL was only stored in a html url field of the feed model. Further, I did not find any places where that field was being used. In the posts that are shown on telescope, there is also a link to the blog (not the feed but the blog page). However, this link is not rendered based on the blog URL. Instead, a blog feed includes a element which has the blog URL, and that is used to link a post to a blog:

  • Nock

    HTTP server mocking and expectations library for Node.js

  • I looked at the service which is used to get the feed URLs from a blog URL and noticed it takes the html response of the blog URL and gets the links ( tags) by checking the type attribute value against a list of valid feed values. So, I decided to use a similar approach by getting the html response for a provided URL and checking the Content-Type header against a list of valid MIME types for a feed. I ended up updating the logic to test if a URL is a feed URL, returning it if true. If the URL is found to not be a feed URL, it would try to get the feed URLs assuming the URL is a blog URL. I tested and confirmed that the new logic worked for both blog and feed URLs. Then, I added some tests for the new function I added to test for a feed URL. Testing this ended up being simpler than I expected as all I had to do was mock the response of a test url (using nock), and then check if the function returned the correct boolean value for a url. I created a PR and noticed that some of the tests in another file were now failing. While I was investigating this, I got a review on my PR, requesting me to add another test to the file which had the failing tests. That file tested the API service as a whole. I found out that nock only mocks a URL's response for one request by default. And since I was now checking for a feed URL as well, the function which returned the feed URLs from a blog URL was throwing an error since the nock for that was used up. To fix this, I had to specify in the nock statement to mock the URL response for two requests:

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • jest

    Delightful JavaScript Testing.

  • However, while running the tests using jest would result in a pass, the expectations would actually fail and the failure result would show up after the tests have already ended. I was confused as to why was happening for a while. Eventually, I noticed this in the file:

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts