<?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: Kuba</title>
    <description>The latest articles on DEV Community by Kuba (@kubaapk).</description>
    <link>https://dev.to/kubaapk</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%2F94703%2F79956722-5d11-4908-9339-d5946b35a35e.png</url>
      <title>DEV Community: Kuba</title>
      <link>https://dev.to/kubaapk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kubaapk"/>
    <language>en</language>
    <item>
      <title>Image processing with Jimp. Optional methods parameters.</title>
      <dc:creator>Kuba</dc:creator>
      <pubDate>Tue, 25 Dec 2018 18:08:35 +0000</pubDate>
      <link>https://dev.to/kubaapk/image-processing-with-jimp-optional-methods-parameters-1k4i</link>
      <guid>https://dev.to/kubaapk/image-processing-with-jimp-optional-methods-parameters-1k4i</guid>
      <description>

&lt;p&gt;Hi guys. &lt;/p&gt;

&lt;p&gt;I'm working on some kind of cloud image hosting and processing. I do use &lt;a href="https://github.com/oliver-moran/jimp"&gt;Jimp&lt;/a&gt;, which is great and works like a charm. &lt;/p&gt;

&lt;p&gt;Jimp's giving a lot of cool image processing methods, such as resizing, scaling and so on. You can chain methods to apply multiple effects, f.ex.:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Jimp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'image/path'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nx"&gt;image&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resize&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;grayscale&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="p"&gt;})&lt;/span&gt;
 &lt;span class="p"&gt;....&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  What do I want to achieve
&lt;/h4&gt;

&lt;p&gt;I want to process images in a fly. For example, I do have an URL:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[...].images.io/i/image-uuid?list=a&amp;amp;of=b&amp;amp;params=c&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;These params can be f.ex. width, height, scale, rotate etc.&lt;/p&gt;

&lt;p&gt;For now I can manipulate image by giving one specific parameter f.ex. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;[...].images.io/i/image-uuid?scale=0.5&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and it's works - it's scaling image.&lt;/p&gt;

&lt;p&gt;But I want to have opportunity to use bunch of options in one request f.ex.:&lt;br&gt;
&lt;code&gt;[...].images.io/i/image-uuid?scale=0.5&amp;amp;filter=grayscale&amp;amp;rotate=80&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and I do not know how make it work. For now - Jimp offers more than 30 methods what gives us bunch of combinations so simple switch-case won't work. ;) &lt;/p&gt;

&lt;p&gt;Basing on documentation, there is no thing such as optional params, and you cannot pass nulls or undefined as a method params.&lt;/p&gt;

&lt;p&gt;Any ideas how can i overcome this? :)&lt;/p&gt;

&lt;p&gt;Happy Holidays everyone! &lt;/p&gt;


</description>
      <category>help</category>
      <category>typescript</category>
      <category>externallibrary</category>
      <category>jimp</category>
    </item>
    <item>
      <title>NodeJS - Unit Tests - testing without hitting database. Confusings.</title>
      <dc:creator>Kuba</dc:creator>
      <pubDate>Tue, 21 Aug 2018 18:04:59 +0000</pubDate>
      <link>https://dev.to/kubaapk/nodejs---unit-tests---testing-without-hitting-database-confusings-3448</link>
      <guid>https://dev.to/kubaapk/nodejs---unit-tests---testing-without-hitting-database-confusings-3448</guid>
      <description>&lt;p&gt;I'm trying to learn TDD approach. I have no troubles with a simple code where I do not need to mock or stub any external methods or dependencies, but where it comes to write tests for some code that based on database I'm getting feel a little bit confused.&lt;/p&gt;

&lt;p&gt;It's clear to me, that the unit tests should tests a small piece of code that do not depends on other services and so on. &lt;/p&gt;

&lt;p&gt;Lets assume that I want to unit test a creating user feature.&lt;/p&gt;

&lt;p&gt;I know that in TDD I should start by writing failing test - but I don't know how it should look like. ;)&lt;/p&gt;

&lt;p&gt;So, here is the example, simplified service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class UserService {

  // typeORM repository
  constructor(userRepository: Repository&amp;lt;User&amp;gt;) {}

  async createAccount(user) {

   // Saves user to database and return created entity object
   return await this.userRepository.save(user);
  } 

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By now I'm able to spy on method and check if is called properly, with correct params etc. (I'm using Jest)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('Should create a user.', async () =&amp;gt; {

  const USER = {
   email: 'test@user.com',
   username: 'user',
   password: 'user',   
  };

  const SPY = jest.fn(() =&amp;gt; USER);
  jest
    .spyOn(userService, 'createAccount')
    .mockImplementation(() =&amp;gt; SPY(USER));

  await userService.createAccount(USER);
  expect(SPY).toHaveBeenCalledTimes(1);
  expect(SPY).toHaveBeenCalledWith(USER);

});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here comes my main question. How should the failing tests looks like? I mean if I stub createAccount method like I did above, it will always pass. Even if the method is empty. It's only requires method declaration. Should I mock repository methods that returns what typeORM is supposed to returns? e.g.:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const REPOSITORY_MOCK = jest.fn(() =&amp;gt; ({
    save: jest.fn().mockImplementation((user) =&amp;gt; user),
}));

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I think that I missed something. :/&lt;/p&gt;

&lt;p&gt;Or Am I try to over complicate it and I should only testing if the method is calling properly? And the whole database related stuff should be test by integration tests where I'm able to work on database?&lt;/p&gt;

&lt;p&gt;I'm looking forward any kind of help. Thank you in advance. &lt;/p&gt;

&lt;p&gt;Cheers, Kuba.&lt;/p&gt;

</description>
      <category>help</category>
      <category>node</category>
      <category>jest</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
