Skip to content

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.

  1. How to fetch and test those API endpoints which is accessible after login into the applications.

    1. Launch the browser navigate to the login page using playwright
    2. Enter the login credentials and submit the form to login.
    3. After successful login, use playwright API to access the API endpoints.
    4. Make API requests and assert the response to validate the functionality
    Example of fetching API after login :


    JavaScript

    // implementation of login test
    
    const apiEndpointURL = "https://example.com/api/endpoint";
    const apiResponse = await page.evaluate(async (url) => {
          const response = await fetch(url);
          return await response.json()
    }, apiEndpointURL)
    
    console.log(apiResponse)


    Thanks
  2. Monkey patching in Ruby is dynamic modification of class. It means overwriting existing methods at runtime
    eg:

    Ruby

    class String
      def reverse
        'Reverse op blocked'
      end
    end
    
    'Hello'.reverse
    >> 'Reverse op blocked'

  3. how to automate the OTP for cypress test

    There is a package called gmail-tester which help use to retrieve mail from the gmail, its have lots of option like from, to, subject, mail_body etc

    Package link :https://github.com/levz0r/gmail-tester

    If you get the able to get the mail then you are good to go to extract OTP from the mail body after extracting otp from the mail you will able to automate the gmail OTP.

    Thanks
  4. Error Monitoring in Bugsnag works similar to Sentry and the commonly used method is bugsnag.notify() . It also takes an error object and captures it as an event. And we can set it up for different environments by using ENV (similar to sentry) or manually configure it as well.
    FYI: Sentry has a broader approval by developers.

    EG:

    JavaScript

    try {
      // Some code here
    } catch (error) {
     bugsnag.notify(
          new Error(`Error ${error} while sending Standup popup`)
        );
    }


  5. In Sentry we have two methods available, captureException() and captureMessage().
    1. captureException() method is used to explicitly report errors and exceptions. We can pass an Error object to captureException() to capture it as an event in Sentry.
    2. captureMessage() method is used to capture a simple message for debugging purposes. Typically, messages captured with captureMessage() are not emitted as events. We can additionally add severity level to this. Available levels are "fatal", "error", "warning", "log", "info", and "debug".
  6. Vaibhav YadavSenior 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.
  7. 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:

    JavaScript

    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.

    JavaScript

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


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

    JavaScript

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


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

    JavaScript

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


    Resources: https://mswjs.io/
  8. Ashwani Kumar JhaSenior 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": "[email protected]",
      "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!
  9. Codemancers
    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.
  10. Ashwani Kumar JhaSenior 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.
  11. Open PR from CLI
    • brew install hub
    • git config --global hub.protocol https
    • hub pull-request (Will create PR for the current branch)
  12. 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).


  13. 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

  14. Ashwani Kumar JhaSenior 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
  15. Etag HTTP Header
    - Etag (also known as entity tag) is a unique identifier for a resource
    - This is used to cache the resources that are unchanged
    - When a request is recieved by server, it generates response and attaches Etag
    - In the subsequent request, application requests for the same resource with If-None-Match header with the value of Etag received in previous step
    - Server compares the value of If-None-match header with Etag identifier value on server
    - If the values match server responds with 304(Not modified) status code with the empty body
    - Application can use the cached response
  16. Get all TODO comments in rails application using rails notes


  17. 1. Learned how to use the slack api.
    2. Learned how to send message on user command through the slack bot.
    3. Learned how to setup and use incoming web hook for slack bot.
    4. Learned How to post message in channel using the incoming web hook.
    5. Learned how to do post req using the axios.


  18. 1. Learned how to make slack bot.
    2. Learned how to use slack bot.
    3. Learned how to add slack bot to the workspace and channel .
    4. Learned how to use brew
    5. Learned how to use ngrok and redirect the local host port to the ngrok url.

Showing page 23 of 42

Your competitors are already using AI. The question is how fast you want to unlock the value.

  • Don't know where to start?

    AI is everywhere but it's unclear which investments will actually move your metrics and which are expensive experiments.

  • Your data isn't ready

    Most AI projects fail at the data layer. Pipelines, quality, access all need work before LLMs can deliver value.

  • Internal teams are stretched

    Your engineers are shipping product. They don't have capacity to also become AI specialists with production-grade experience.

  • Legacy systems block everything

    Aging, undocumented codebases make AI integration slow, risky, and expensive. They need to move first.

Don't worry. We've got you covered.

Start with the audit.

Book a free discovery call