DEV Community

Tue
Tue

Posted on

Final progress update

Last week was fun and quite productive, I finally finished the backend part of the issue and the PR for the front-end is up for review.

Adding a test for the endpoint:

Any new feature should have a test suite for it, I wrote the test below to make sure the data returned is correct. There are a few checks like status of the request, the type of data returned and making sure all keys are correct.

test('Should return 200 and valid response object', async () => {
    function checkKeys(resBody) {
      const allKeys = ['waiting', 'active', 'completed', 'failed', 'delayed', 'paused', 'jobCnt'];
      return Object.keys(resBody.queueInfo).every((key) => {
        if (!allKeys.includes(key) || typeof resBody.queueInfo[key] !== 'number') {
          return false;
        }
        return true;
      });
    }

    const res = await request(app).get('/feeds/info');

    expect(res.status).toEqual(200);
    expect(typeof res.body).toEqual('object');
    expect(typeof res.body.queueInfo).toEqual('object');
    expect(checkKeys(res.body)).toBe(true);
  });
Enter fullscreen mode Exit fullscreen mode

Adding the job count to the dashboard:

The dashboard of telescope was recently updated using handlebars template, so it was a good opportunity to brush up my knowledge of it. You can take a look at the dashboard and the job count gets updated when the feed queue starts processing in the backend

I simply created function to fetch the endpoint I feeds/info and exported it to the render method of the hbs template. I have more detailed explanation in this PR. For now, I'm waiting for some new fixes to the dashboard to land and fix the fetch url accordingly.

Discussion (0)