TILs - Fueling Curiosity, One Insight at a Time

At Codemancers, we believe every day is an opportunity to grow. This section is where our team shares bite-sized discoveries, technical breakthroughs and fascinating nuggets of wisdom we've stumbled upon in our work.

Published
Author
user-image
Vaibhav Yadav
Senior System Analyst
Local storage does not work right off the bat when we render a web page within an App. App Dev will have to ensure that DOM storage is enable for it to work.
Published
Author
user-image
Syed Sibtain
System Analyst
Mocking useSWR directly in test cases is a little complicated and even not recommended at some places.
So the ideal way to do it is using a library Mock Service Worker. Here are the steps that helped me solve this.
1. Create a mock server using setupServer from msw/node:

Code

const server = setupServer(
  rest.get(`/api/channels/C04UPJ9243E/members`, (req, res, ctx) => {
    return res(
      ctx.json({
        members: [{ name: "Sibtain", image: "abcd.jsp", id: 123 }],
      })
    );
  })
);


2. Start the server and after we run the test, close the server.

Code

beforeAll(() => server.listen());
afterAll(() => server.close());


3. To ensure clean and isolated tests, reset the request handlers.

Code

afterEach(() => server.resetHandlers());


Now our API connections are taken care of and we can render components and run the test cases.

Code

test('render stuff, () => {
}


Resources: https://mswjs.io/
Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
While writing Cypress test we generally create a cypress.env.json file to store the environment variables.


Code

{
  "BASE_URL": "https://company.dev.com/",
  "USER_EMAIL": "ashwani@example.com",
  "USER_PASSWORD": "Test@12345",
}


To retrieve the value of our environment variable, we use the Cypress.env method in the test file.


Code

const baseUrl = Cypress.env('BASE_URL');


That's all we need to do locally to use the env vars in our Cypress test.

Now for CI, we can save these environment variables as Github action secrets.

To make these environment variables accessible from Github action secrets to our test, we need to keep a few things in mind.

• Add a value of empty string to the env vars and expose the cypress.env.json file.

Code

{
       "BASE_URL": "",
       "USER_EMAIL": "",
       "USER_PASSWORD": "",
  }


• We need to add CYPRESS_ prefix to the env vars in the yml file.

Code

env:
       CYPRESS_BASE_URL: ${{ secrets.BASE_URL }}
       CYPRESS_USER_EMAIL: ${{ secrets.USER_EMAIL }}
       CYPRESS_USER_PASSWORD: ${{ secrets.USER_PASSWORD }}


Happy testing!
Published
Author
user-image
Ananth
If Postgres logical replication is enabled via pglogical extension, below query can be used to check the size WAL Folder.
select sum(size) from pg_ls_waldir(); (Response to the query is in Bytes)

This is the folder where the WAL logs are stored, which is utilized for postgres data replication from master to slave. In case there is any lag or problems with replication the logs will get accumulating in the folder, spiking the disk storage and can cause downtime of the database it self.
Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
In the first server-side rendering (SSR) page render, the router.query may not be populated immediately. To handle this scenario, we can add a check to ensure that the redirection happens only on the client-side, once the router.query values are available.


Code

import { useEffect } from 'react';
import { useRouter } from 'next/router';

export const ResetPasswordPage = () => {
  const { push, query, isReady } = useRouter();
  const { username, code } = query as ResetPasswordPageQuery;
   ...
  useEffect(() => {
    if (isReady && (!username || !code)) {
      push('/login');
    }
  }, [isReady, username, code, push]);
  ...
};


Here the isReady property from useRouter is used to determine if the router is ready and router.query is populated.
This way, the initial SSR render won't trigger the redirection, and the user will be redirected to the login page only on the client-side if the necessary parameters are missing from the URL.
Published
Author
user-image
Sujay
Open PR from CLI
• brew install hub
• git config --global hub.protocol https
• hub pull-request (Will create PR for the current branch)
Published
Author
user-image
Ayush Srivastava
System Analyst
Term called fuzzy searching
fuzzy searching (more formally known as approximate string matching) is the technique of finding strings that are approximately equal to a given pattern (rather than exactly).
Published
Author
user-image
Rishav Raj
System Analyst


I learned how to use promise.all to combine multiple api calls.
Learned how to made api endpoint by using app directory and page directory in Next Js.

Learned how to implement slack bolt app with next js using the bolt http runner npm package

Learned how to use node-cron to schedule message

Published
Author
user-image
Ashwani Kumar Jha
Senior System Analyst
The Active Record Pattern popularised by Ruby on Rails goes against the modularity provided by Nest.Js.

Nest.js encourages the use of the Repository pattern.

Data Mapper/Repository pattern:

• Separates data access logic from business logic
• Data Mapper: Maps data between domain objects and the database
• Repository: Provides methods for querying and manipulating domain objects
• Promotes separation of concerns, testability, and maintainability
Active Record:

• Combines data access and business logic within domain objects
• Domain objects encapsulate database interactions
• Simplifies development by allowing direct manipulation of objects
• Can make separation of concerns and independent testing more challenging

Showing 44 to 46 of 82 results

Ready to Build Something Amazing?

Codemancers can bring your vision to life and help you achieve your goals