<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Smriti Rastogi</title>
    <description>The latest articles on DEV Community by Smriti Rastogi (@smritirgi).</description>
    <link>https://dev.to/smritirgi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F849024%2F44fc49d1-a1b2-49c6-8cbe-38162c856855.jpeg</url>
      <title>DEV Community: Smriti Rastogi</title>
      <link>https://dev.to/smritirgi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/smritirgi"/>
    <language>en</language>
    <item>
      <title>Is this how you test Node cron jobs?</title>
      <dc:creator>Smriti Rastogi</dc:creator>
      <pubDate>Fri, 19 May 2023 09:14:57 +0000</pubDate>
      <link>https://dev.to/smritirgi/is-this-how-you-test-node-cron-jobs-3ah7</link>
      <guid>https://dev.to/smritirgi/is-this-how-you-test-node-cron-jobs-3ah7</guid>
      <description>&lt;p&gt;I have a node cron job in my application that looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const taskOne = (time) =&amp;gt; {
   const loadData = schedule(time , ()=&amp;gt;{

}
loadData.start();

}

taskOne("23 04 * * 0-6")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;The way I wrote it this was because the same logic runs two times in a day so did not want to write the logic again.&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The way I am trying to test is:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe("cron jobs", () =&amp;gt; {
    let year, month, day;
    beforeAll(() =&amp;gt; {
      const date = new Date();
      year = date.getFullYear();
      month = String(date.getMonth()).padStart(2, "0");
      day = String(date.getDate()).padStart(2, "0");
    });

    it("run taskOne node cron job", async () =&amp;gt; {
      const currentHour = new Date().getHours();
      let currentMinutes = String(new Date().getMinutes()).padStart(2, "0");
      if (currentMinutes == `60`) currentMinutes = `01`;
      taskOne(`${currentMinutes} ${currentHour} * * 0-6`);
      setTimeout(() =&amp;gt; {
        //expect statements
        done();
      }, 300000);
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above test passes but these cron jobs take a long time to finish (could be 30 -60 minutes) so it is getting difficult to decide when should I do the assertions using expect statement. Currently I am doing it after a wait for 5 minutes to verify some of the tasks that usually completes within that time. &lt;/p&gt;

&lt;p&gt;Another issue is how to stop these cron jobs after I do my assertions otherwise jest throws below warnings:Jest did not exit one second after the test run has completed.&lt;/p&gt;

&lt;p&gt;'This usually means that there are asynchronous operations that weren't stopped in your tests.'&lt;/p&gt;

</description>
      <category>node</category>
      <category>jest</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to restrict access using api keys?</title>
      <dc:creator>Smriti Rastogi</dc:creator>
      <pubDate>Sat, 03 Sep 2022 10:51:51 +0000</pubDate>
      <link>https://dev.to/smritirgi/how-to-restrict-access-using-api-keys-564p</link>
      <guid>https://dev.to/smritirgi/how-to-restrict-access-using-api-keys-564p</guid>
      <description>&lt;p&gt;How do we restrict access using api keys?&lt;br&gt;
Links to articles / videos will be helpful&lt;/p&gt;

</description>
      <category>api</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Issue with React Context</title>
      <dc:creator>Smriti Rastogi</dc:creator>
      <pubDate>Sun, 01 May 2022 03:28:15 +0000</pubDate>
      <link>https://dev.to/smritirgi/issue-with-react-context-3j1p</link>
      <guid>https://dev.to/smritirgi/issue-with-react-context-3j1p</guid>
      <description>&lt;p&gt;&lt;strong&gt;I am getting error - Uncaught TypeError: Cannot destructure property 'temperature' of '(0 , react_&lt;em&gt;WEBPACK_IMPORTED_MODULE_0&lt;/em&gt;_.useContext)(...)' as it is undefined at Settings (Settings.js:12:1)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;userSettingContext.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; import React , {useState} from 'react';
 import Settings from './Settings';

 const settingContext  = React.createContext();

 function UserSettingContext() {
    const [temperature ,setTemperature] = useState("Celsius");
    const [pressure , setPressure] = useState("HectoPascal");

    return (
        // the component that provides the value
        &amp;lt;settingContext.Provider value={{temperature : [temperature ,  setTemperature] , 
            pressure: [pressure, setPressure]}}&amp;gt;
           &amp;lt;Settings/&amp;gt;
        &amp;lt;/settingContext.Provider&amp;gt;
    )
}

export {settingContext , UserSettingContext };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Settings.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; import React , {useContext, useState} from 'react';
 import { Modal } from 'react-bootstrap';
 import {settingContext} from './UserSettingContext.js';
 import {FiSettings} from 'react-icons/fi';
 import './Settings.css';

function Settings() {

      const [show ,  setShow] = useState(false);
      const handleClose = () =&amp;gt; setShow(false);
      const handleShow = () =&amp;gt; setShow(true);

      const {temperature  , pressure } = useContext(settingContext);

      return (
               &amp;lt;&amp;gt;
                    &amp;lt;FiSettings onClick={handleShow} /&amp;gt;
                               &amp;lt;Modal show={show} onHide ={handleClose}&amp;gt;
                               &amp;lt;Modal.Header closeButton&amp;gt;
                                         &amp;lt;Modal.Title&amp;gt;User Settings&amp;lt;/Modal.Title&amp;gt;
                               &amp;lt;/Modal.Header&amp;gt;
                               &amp;lt;Modal.Body&amp;gt;
                                         &amp;lt;label className='temperature'&amp;gt; Temperature
                                              Celsius &amp;lt;input type="checkbox" /&amp;gt; Fahrenheit
                                         &amp;lt;/label&amp;gt;
                                         &amp;lt;label className='pressure'&amp;gt; Pressure
                                              &amp;lt;input type="checkbox" /&amp;gt;
                                         &amp;lt;/label&amp;gt;
                                 &amp;lt;/Modal.Body&amp;gt;
                               &amp;lt;/Modal&amp;gt;
               &amp;lt;/&amp;gt;

      )
}

export default Settings;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks in advance&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>context</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
