<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Oswaldo Oliveira on Medium]]></title>
        <description><![CDATA[Stories by Oswaldo Oliveira on Medium]]></description>
        <link>https://medium.com/@oswaldo.dev.oliveira?source=rss-94f6642dcc06------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CaCvbKQXw6ZM-oz9mmmrdg.jpeg</url>
            <title>Stories by Oswaldo Oliveira on Medium</title>
            <link>https://medium.com/@oswaldo.dev.oliveira?source=rss-94f6642dcc06------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 23:29:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@oswaldo.dev.oliveira/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Comprehensive Guide to IAM on AWS: Managing Identity and Access]]></title>
            <link>https://medium.com/@oswaldo.dev.oliveira/comprehensive-guide-to-iam-on-aws-managing-identity-and-access-9e30ac10a22c?source=rss-94f6642dcc06------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e30ac10a22c</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[iam-roles]]></category>
            <dc:creator><![CDATA[Oswaldo Oliveira]]></dc:creator>
            <pubDate>Tue, 16 Apr 2024 20:59:32 GMT</pubDate>
            <atom:updated>2024-04-16T20:59:32.764Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ff7J3EsqbIOim_10FEiZMA.jpeg" /></figure><p>If you’re a software developer embarking on the AWS (Amazon Web Services) journey, understanding IAM (Identity and Access Management) is essential. IAM serves as the gatekeeper to your cloud infrastructure, allowing you to control who has access to your resources and what actions they can perform.</p><h3>What is IAM?</h3><p>IAM, or Identity and Access Management, is the AWS service designed to manage identities and access within your cloud environment. Think of it as a security control system, where you can create and manage users, groups, and roles, defining who can do what in your infrastructure.</p><h3>Users, Groups, and Roles</h3><p>In IAM, users represent the individuals or entities interacting with your AWS account. You can create users for each member of your team and assign them specific permissions.</p><p>Groups are logical sets of users with similar permissions. This simplifies the management process, as you can assign permissions to a group and add or remove users as needed, maintaining consistency in access policies.</p><p>Roles, on the other hand, are entities you can create and temporarily grant to users, services, or resources. They are useful in scenarios where you need to grant temporary access, such as allowing one AWS service to access another service in your account.</p><h3>Creating Groups and Users</h3><p>Now that we understand the IAM hierarchy, let’s take a look at how to create groups and users.</p><h4>Creating Groups</h4><p>Groups are a convenient way to manage permissions in bulk. By grouping users with similar permissions, you simplify the process of granting and revoking access.</p><p>To create a group, navigate to the IAM console, click on “Groups,” then “Create group.” You’ll be prompted to assign a name to the group and select the desired permissions. Once created, you can add users to that group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NqLThmG8gKAIn4th76czIw.png" /></figure><h4>Creating Users</h4><p>Users are the entities that interact directly with your AWS account. Each user has their own login credentials and can be added to one or more groups to receive the appropriate permissions.</p><p>To create a user, go to the IAM console, click on “Users,” and then “Add user.” You’ll need to provide a username and select the access options, including adding the user to existing groups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GoMlICBQKexkOLPbiRjBdA.png" /></figure><h3>IAM Identity Center: Expanding Management</h3><p>Now that you’ve learned the basics of IAM, let’s explore an advanced tool: IAM Identity Center.</p><p>IAM Identity Center offers all the functionalities of standard IAM but goes beyond, allowing the management of third-party application access hosted within AWS. To utilize IAM Identity Center, you need to have an organization set up within the AWS console.</p><h3>Strengthening Security with MFA</h3><p>Security is a primary concern in AWS, and an effective way to protect your accounts is through Multi-Factor Authentication (MFA). MFA adds an extra layer of security by requiring not only a password but also a second form of authentication, such as a code generated by an authentication app or a hardware token.</p><p>Enabling MFA in your AWS console is straightforward and highly recommended. Simply access your user’s security settings, select the option to enable MFA, and follow the instructions to set up two-factor authentication.</p><h3>Financial Management with AWS Organizations</h3><p>In addition to managing identities and access, IAM also plays a key role in controlling the financial aspects of your AWS account, especially when combined with AWS Organizations.</p><p>AWS Organizations is a service that allows you to consolidate and manage multiple AWS accounts within a single organization. This simplifies billing, facilitates the management of shared resources, and enables the establishment of centralized access policies for all accounts.</p><p>By creating an AWS organization from the outset of console usage, you establish a solid framework for financial and operational management of your cloud services.</p><h3>Reinforcing Password Policies</h3><p>Robust password policies are essential to maintaining the security of your accounts in AWS. Fortunately, IAM offers powerful features for configuring and enforcing these policies.</p><p>You can set policies that specify the minimum number of characters, require a mix of uppercase and lowercase letters, numbers, and special characters, and even set an expiration period for passwords. This ensures that your credentials remain secure and up-to-date over time.</p><h3>Using CLI and CloudShell for Management</h3><p>For developers and administrators accustomed to working on the command line, AWS offers two powerful tools: AWS CLI and CloudShell.</p><p>AWS CLI is a unified tool that allows you to manage all aspects of your AWS services directly from the command line. With it, you can create users, configure access policies, provision resources, and more, all in an automated and programmatic manner.</p><p>CloudShell, on the other hand, is a command line integrated directly into the AWS console. It offers a ready-to-use Linux machine, allowing you to run CLI commands and access your AWS resources from anywhere, without needing to configure or install anything.</p><h3>AWS Access Key, SDK, and Audit Tools</h3><p>When interacting with AWS programmatically, you’ll need access keys and the AWS SDK. Access keys consist of an Access Key and a Secret Key, which are used to authenticate requests to the AWS API. It’s essential to protect these keys like any other sensitive credential.</p><p>The AWS SDK, or Software Development Kit, provides a convenient way to interact with AWS services in your applications. With the SDK, you can write code to automate tasks, integrate AWS services into your applications, and create custom solutions for your specific needs.</p><p>Additionally, IAM offers powerful audit tools, such as the Credential Report and Access Advisor. The Credential Report provides a detailed view of your users’ credentials, while the Access Advisor shows which services are being accessed and by whom.</p><h3>Conclusion: Fortifying Security and Management on AWS</h3><p>IAM plays a critical role in security and identity management on AWS. By understanding and implementing IAM best practices, you strengthen the security of your cloud infrastructure and simplify the process of managing users and permissions.</p><p>In this guide, we’ve explored the basics of IAM, from creating users and groups to configuring password policies and using advanced tools like IAM Identity Center and AWS Organizations. We’ve also discussed the importance of MFA in securing the AWS console and how to leverage CLI, CloudShell, Access Key, and SDK for automation and simplification.</p><p>By implementing the recommended practices outlined in this guide, you’ll be better prepared to protect your resources on AWS, manage identities and access efficiently, and ensure compliance with your organization’s security policies.</p><p>Whether you’re a newcomer to AWS or an experienced user, IAM is a key piece of the cloud security puzzle. By mastering its functionalities and integrating it into your security practices, you’re building a solid foundation for success in the cloud.</p><p>We hope this guide has been helpful, and that you can apply this knowledge to strengthen security and management in your AWS infrastructure. If you have any questions or need further assistance, don’t hesitate to seek more information in the official AWS documentation or contact AWS support team.</p><p>Thank you for reading, and good luck on your AWS journey!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e30ac10a22c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is AWS and Why Should You Consider Cloud Computing]]></title>
            <link>https://medium.com/@oswaldo.dev.oliveira/what-is-aws-and-why-should-you-consider-cloud-computing-424f4fb8eb6a?source=rss-94f6642dcc06------2</link>
            <guid isPermaLink="false">https://medium.com/p/424f4fb8eb6a</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[aws-certification]]></category>
            <dc:creator><![CDATA[Oswaldo Oliveira]]></dc:creator>
            <pubDate>Tue, 09 Apr 2024 21:00:41 GMT</pubDate>
            <atom:updated>2024-04-09T21:00:41.370Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G9oZwylScit6bSM7dpbUdg.jpeg" /></figure><h3>What is Cloud Computing?</h3><p>Imagine having your own server room, complete with all the necessary hardware and infrastructure to run your business smoothly. Now, envision having access to all those resources without the hassle of maintaining a physical server room. That’s precisely what Cloud Computing offers.</p><p>Instead of managing everything locally, Cloud Computing allows you to store and process data in remote data centers, such as the ones provided by AWS. This means you can access your services from anywhere, at any time, as long as you have an internet connection. Moreover, Cloud Computing presents numerous advantages, including cost reduction, global scalability, enhanced performance, agility, productivity, security, and flexibility.</p><h3>Advantages of Cloud Computing</h3><ul><li><strong>Cost Reduction:</strong> By eliminating the need to invest in expensive hardware like physical servers, you can pay only for the resources you utilize, leading to long-term cost savings.</li><li><strong>Global Scalability:</strong> With the ability to deploy services in various regions worldwide, Cloud Computing is perfect for businesses catering to diverse international markets.</li><li><strong>Enhanced Performance:</strong> Cloud Computing offers robust computing and storage resources, significantly improving the performance of your applications and services.</li><li><strong>Agility:</strong> You can launch services within minutes, ideal for businesses that require swift adaptation to market demands.</li><li><strong>Productivity:</strong> Cloud Computing enables you to focus on your core business activities, freeing you from the burdens of hardware and software maintenance.</li><li><strong>Security:</strong> Advanced security features like data encryption and multi-factor authentication safeguard your data and applications from potential threats.</li><li><strong>Flexibility and Remote Accessibility:</strong> Access your services from anywhere, on any device, making Cloud Computing ideal for businesses with remote teams.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JMMDASa6l4sV4tl0w2YOQg.jpeg" /></figure><h3>Types of Cloud Computing</h3><p>There are three primary types of Cloud Computing:</p><ul><li><strong>Infrastructure as a Service (IAAS):</strong> Provides fundamental infrastructure such as servers, virtual machines (VMs), and storage, ideal for businesses seeking complete control over their infrastructure without the maintenance overhead.</li><li><strong>Platform as a Service (PAAS):</strong> Offers a platform for hosting applications and services, including operating systems and databases, allowing businesses to focus on application development rather than infrastructure management.</li><li><strong>Software as a Service (SAAS):</strong> Delivers complete applications as services, such as email and collaboration tools, relieving businesses of software maintenance responsibilities.</li></ul><h3>Types of Cloud Deployment</h3><p>Cloud deployment models include:</p><ul><li><strong>Public Cloud:</strong> Operated by cloud providers like AWS, Azure, and GCP, accessible to anyone via the internet, and offering unlimited computing and storage resources.</li><li><strong>Private Cloud:</strong> Operated by businesses for their exclusive use, providing high levels of security and control over data and applications.</li><li><strong>Hybrid Cloud:</strong> Combines elements of public and private clouds, allowing businesses to leverage both for different workloads as needed.</li></ul><h3>Conclusion</h3><p>In conclusion, delving into AWS and Cloud Computing opens up a realm of possibilities and efficiencies for businesses and developers alike. The advantages of Cloud Computing, including cost-effectiveness, scalability, performance optimization, agility, productivity enhancement, robust security, and unmatched flexibility, underscore the transformative potential of cloud technology.</p><p>As you embark on your journey into the AWS ecosystem and explore the intricacies of Cloud Computing, remember that the cloud offers not just technological solutions but a paradigm shift in how we approach computing and innovation. Embrace the cloud, harness its capabilities, and unlock new horizons in software development and beyond.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=424f4fb8eb6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[☁️ Unveiling the Power of Amazon S3 Uploads with NestJS]]></title>
            <link>https://medium.com/@oswaldo.dev.oliveira/%EF%B8%8F-unveiling-the-power-of-amazon-s3-uploads-with-nestjs-b7bfa64a115c?source=rss-94f6642dcc06------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7bfa64a115c</guid>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Oswaldo Oliveira]]></dc:creator>
            <pubDate>Wed, 31 Jan 2024 20:49:35 GMT</pubDate>
            <atom:updated>2024-01-31T20:49:35.275Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pAKAk0UevhWtT8-f" /></figure><p>Hello developers! 🚀 Today, let’s embark on an exciting journey into the enchanting world of Amazon S3 and learn how to perform file uploads like magic using the NestJS framework. Grab your wands (or keyboards), and let’s make some files disappear and reappear in the cloud!</p><h3>What is Amazon S3?</h3><p>Picture this: a mystical land known as Amazon S3 (Simple Storage Service), a realm of object storage that offers industry-leading scalability, data availability, security, and performance. It’s like a superhero for storing and safeguarding any volume of data. Whether dealing with data lakes, websites, mobile applications, or big data analytics — Amazon S3 has got your back.</p><h3>How to Use the Amazon S3 API with NestJS</h3><p>In our magical journey, we’ll harness the powers of NestJS, TypeScript, Vitest, and a sprinkle of functional error handling (Either). First, we need to add the multer package, following the wisdom from the NestJS documentation:</p><pre>npm i @types/multer -D</pre><p>Now, let’s create the controller to handle attachments.</p><h3>The Controller</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TsY7hZr5iheYO1YGe0phvg.png" /></figure><p>Here, we create an endpoint that accepts attachments up to 2MB, restricting them to <strong>PNG</strong>, <strong>JPG</strong>, <strong>JPEG</strong>, or <strong>PDF</strong>.</p><p>Now, let’s create the use case to save this attachment in the database.</p><h3>The Use Case</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ToJz7To9RZCqD0i2qDFrhw.png" /></figure><p>We use the body as a buffer because these magical scrolls (files) are small (2MB). For larger files like videos and audios, we might consider a streaming strategy.</p><p>At the heart of our magical land lies the Uploader class, using the <a href="http://twitter.com/aws">@aws</a>-sdk/client-s3 package.</p><p>The Uploader</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bbqXSt7XJ1x6BjVp1fD2nQ.png" /></figure><p>This Uploader class uses the s3Client to configure the route to our bucket and the magical tokens.</p><p>Finally, let’s sprinkle a bit of real magic with an end-to-end test, testing the actual request with a file.</p><p>The Test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1KSPia_6PCQBFsvPvriskw.png" /></figure><p>Running this test, behold! The file is saved in the Cloudflare realm.</p><h3>Conclusion</h3><p>Amazon S3 is a powerful tool for efficiently uploading files, and NestJS is our trusted magic wand on this journey. As you embark on your adventures, remember — the cloud is your canvas, and Amazon S3 is your magic brush.</p><h3>If You Seek More Wisdom</h3><p><a href="https://medium.com/@oswaldo.dev.oliveira/ditch-the-try-catch-desert-unleash-the-oasis-of-functional-error-handling-with-either-018d2e13061c">Ditch the Try/Catch Desert: Unleash the Oasis of Functional Error Handling with Either</a></p><p><a href="https://blog.stackademic.com/how-to-boost-your-node-js-app-performance-with-e2e-tests-6cb22c9c8465">🌟 How to Boost Your Node.js App Performance with E2E Tests</a></p><p><a href="https://developers.cloudflare.com/r2/">Cloudflare R2 · Cloudflare R2 docs</a></p><p><a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html">What is Amazon S3? — Amazon Simple Storage Service</a></p><p>May your code be magical, and your files be secure in the cloud! 🌟</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7bfa64a115c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ How to Boost Your Node.js App Performance with E2E Tests]]></title>
            <link>https://blog.stackademic.com/how-to-boost-your-node-js-app-performance-with-e2e-tests-6cb22c9c8465?source=rss-94f6642dcc06------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cb22c9c8465</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[test]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Oswaldo Oliveira]]></dc:creator>
            <pubDate>Wed, 17 Jan 2024 00:24:38 GMT</pubDate>
            <atom:updated>2024-01-22T01:42:57.526Z</atom:updated>
            <content:encoded><![CDATA[<p>E2E tests are essential for ensuring that your Node.js app works as expected from start to finish. But how do you perform E2E tests effectively and avoid common pitfalls? In this blog post, I will show you how to set up and run E2E tests in a Node.js app using NestJS, Prisma, Vitest and superTest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5oJTXSylATp-2A5HueSMYQ.png" /></figure><h3>What are E2E tests</h3><p>E2E tests, also known as end-to-end tests, are a type of testing that simulates the real user behavior and interactions with your app. They cover the entire flow of your app, from the front-end to the back-end, and verify that all the components work together as intended.</p><p>E2E tests are different from unit tests and integration tests, which focus on testing individual units or modules of your app. E2E tests are more comprehensive and realistic, but also more complex and time-consuming.</p><p>E2E tests can help you:</p><ul><li>Detect bugs and errors that might not be caught by other types of testing</li><li>Ensure that your app meets the user requirements and expectations</li><li>Validate the functionality and usability of your app</li><li>Increase the confidence and quality of your app</li></ul><h3>How to perform E2E tests</h3><p>To perform E2E tests in a Node.js app, you need to follow these steps:</p><ul><li>Configure the Vitest and setup files</li><li>Write the test file</li><li>Run the tests</li></ul><h3>Configure the Vitest and setup files</h3><p>The first step is to configure the Vitest and setup files for your E2E tests. Vitest is a fast and lightweight testing framework for Node.js, which supports ESM, TypeScript, and Jest-like syntax. You can install it with the following command:</p><pre>npm install vitest --save-dev</pre><p>You need to create a vitest.config.ts file in the root directory of your app, and specify the options for the Vitest framework. For example, your vitest.config.ts file might look like this:</p><pre>import swc from &#39;unplugin-swc&#39;<br>import { defineConfig } from &#39;vitest/config&#39;<br>import tsConfigPaths from &#39;vite-tsconfig-paths&#39;<br><br>export default defineConfig({<br>  test: {<br>    include: [&#39;**/*.e2e-spec.ts&#39;],<br>    globals: true,<br>    root: &#39;./&#39;,<br>    setupFiles: [&#39;./test/setup-e2e.ts&#39;],<br>  },<br>  plugins: [<br>    tsConfigPaths(),<br>    swc.vite({<br>      module: { type: &#39;es6&#39; },<br>    }),<br>  ],<br>})</pre><p>You also need to create a test/setup-e2e.ts file in the root directory of your app, and write the code to start and stop your app before and after the tests. For example, your test/setup-e2e.ts file might look like this:</p><pre>import &#39;dotenv/config&#39;<br>import { PrismaClient } from &#39;@prisma/client&#39;<br>import { randomUUID } from &#39;node:crypto&#39;<br>import { execSync } from &#39;node:child_process&#39;<br><br>const prisma = new PrismaClient()<br><br>function generateUniqueDatabaseURL(schemaId: string) {<br>  if (!process.env.DATABASE_URL) {<br>    throw new Error(&#39;Please provider a DATABASE_URL environment variable.&#39;)<br>  }<br><br>  const url = new URL(process.env.DATABASE_URL)<br><br>  url.searchParams.set(&#39;schema&#39;, schemaId)<br><br>  return url.toString()<br>}<br><br>const schemaId = randomUUID()<br><br>beforeAll(async () =&gt; {<br>  const databaseURL = generateUniqueDatabaseURL(schemaId)<br><br>  process.env.DATABASE_URL = databaseURL<br><br>  execSync(&#39;npx prisma migrate deploy&#39;)<br>})<br><br>afterAll(async () =&gt; {<br>  await prisma.$executeRawUnsafe(`DROP SCHEMA IF EXISTS &quot;${schemaId}&quot; CASCADE`)<br>  await prisma.$disconnect()<br>})</pre><h3>Write the test file</h3><p>The next step is to write the test file for your E2E tests. You need to create a test/app.e2e-spec.ts file in the root directory of your app, and write the test cases using the Vitest and superTest packages. superTest is a library for testing HTTP servers and APIs, which allows you to make requests and assert responses. You can install it with the following command:</p><pre>npm install supertest --save-dev</pre><p>Then, you can write the test cases for each endpoint of your app, using the test function to describe the test name, and the expect function to assert the expected results. You can use the request function to make HTTP requests to your app, and chain methods to specify the headers, body, query, etc. For example, your test/app.e2e-spec.ts file might contain the following test case:</p><pre>import { AppModule } from &#39;@/infra/app.module&#39;<br>import { PrismaService } from &#39;@/infra/database/prisma/prisma.service&#39;<br>import { INestApplication } from &#39;@nestjs/common&#39;<br>import { Test } from &#39;@nestjs/testing&#39;<br>import request from &#39;supertest&#39;<br><br>describe(&#39;Create account (E2E)&#39;, () =&gt; {<br>  let app: INestApplication<br>  let prisma: PrismaService<br><br>  beforeAll(async () =&gt; {<br>    const moduleRef = await Test.createTestingModule({<br>      imports: [AppModule],<br>    }).compile()<br><br>    app = moduleRef.createNestApplication()<br>    prisma = moduleRef.get(PrismaService)<br><br>    await app.init()<br>  })<br><br>  test(&#39;[POST] /accounts&#39;, async () =&gt; {<br>    const response = await request(app.getHttpServer()).post(&#39;/accounts&#39;).send({<br>      name: &#39;John Doe&#39;,<br>      email: &#39;john.doe@example.com&#39;,<br>      password: &#39;123456&#39;,<br>    })<br><br>    expect(response.statusCode).toBe(201)<br><br>    const userOnDatabase = await prisma.user.findUnique({<br>      where: {<br>        email: &#39;john.doe@example.com&#39;,<br>      },<br>    })<br><br>    expect(userOnDatabase).toBeTruthy()<br>  })<br>})</pre><h3>Run the tests</h3><p>The final step is to run the E2E tests and check the results. You can use the vitest command to run the tests, and specify the --config option to use the vitest.config.e2e.ts file. For example, you can run the following command in the terminal:</p><pre>vitest run --config ./vitest.config.e2e.ts</pre><h3>Conclusion</h3><p>You’ve just learned how to set up and run E2E tests in a Node.js app using NestJS, Prisma, Vitest and superTest. E2E tests are a powerful way to ensure that your app functions correctly and meets the user expectations. By following the steps in this post, you can create a separate environment for your tests, configure the Vitest framework and setup files, write the test cases for each endpoint, and run the tests with ease.</p><p>E2E testing is not only a good practice, but also a rewarding skill that can boost your app performance and quality. If you want to take your E2E testing skills to the next level, you can check out these resources:</p><ul><li><a href="https://vitest.dev/guide/">Vitest Documentation</a></li><li><a href="https://www.npmjs.com/package/supertest">superTest Documentation</a></li></ul><p>I hope you enjoyed this blog post and found it useful. If you have any questions or feedback, please leave a comment below. And if you liked this post, please share it with your friends and colleagues. Thank you for reading! 😊</p><h3>Stackademic</h3><p>Thank you for reading until the end. Before you go:</p><ul><li>Please consider <strong>clapping</strong> and <strong>following</strong> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/stackademic"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/c/stackademic"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a></li><li>Visit our other platforms: <a href="https://plainenglish.io/"><strong>In Plain English</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cb22c9c8465" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/how-to-boost-your-node-js-app-performance-with-e2e-tests-6cb22c9c8465">🌟 How to Boost Your Node.js App Performance with E2E Tests</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ditch the Try/Catch Desert: Unleash the Oasis of Functional Error Handling with Either]]></title>
            <link>https://medium.com/@oswaldo.dev.oliveira/ditch-the-try-catch-desert-unleash-the-oasis-of-functional-error-handling-with-either-018d2e13061c?source=rss-94f6642dcc06------2</link>
            <guid isPermaLink="false">https://medium.com/p/018d2e13061c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Oswaldo Oliveira]]></dc:creator>
            <pubDate>Tue, 19 Dec 2023 21:10:16 GMT</pubDate>
            <atom:updated>2023-12-19T21:35:30.433Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ro4jpQxwkWn3DEXDE8GZWw.jpeg" /></figure><p>Hey TypeScript warriors, gather around! Today, we’re leaving the dusty plains of traditional try/catch behind and venturing into the lush oasis of functional error handling. We’ll trade those tumbleweeds of exceptions for the elegant power of the Either type, transforming your code from a spaghetti western into a serene zen garden.</p><p><strong>Try/Catch: The Gritty Gunslinger</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0YIrz7UPgp_znCraOp7oLA.jpeg" /></figure><p>Let’s face it, traditional try/catch feels like a wild west saloon brawl. You wrestle with cryptic errors, dodge unexpected bullets, and pray you haven’t missed a lurking gremlin in the code. Here’s a classic gunslinger scenario:</p><pre>try {<br>  const treasure = digForGold(mineEntrance);<br>  if (!treasure) {<br>    throw new EmptyMineError();<br>  } <br>  console.log(&quot;I struck gold!&quot;);<br>} catch (error) {<br>  console.error(`Darn! ${error}`);<br>}</pre><p>It works, but it’s messy and unpredictable. Errors lurk in shadows, and logic gets tangled in conditional spaghetti.</p><p><strong>Enter the Either: A Masterful Samurai</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*brti152U0jlW8ppy0dmcXg.jpeg" /></figure><p>Functional programming offers a new path, not with six-shooters but with the wisdom of samurai. The Either type acts as a skilled combatant, wielding both success (Right) and errors (Left) with grace and clarity. Imagine them as two sides of a polished katana:</p><pre>class Left&lt;E&gt; {<br>  constructor(readonly value: E) {}<br>  isLeft(): this is Left&lt;E&gt; {<br>    return true;<br>  }<br>  isRight(): this is Right&lt;never&gt; {<br>    return false;<br>  }<br>}<br><br>class Right&lt;A&gt; {<br>  constructor(readonly value: A) {}<br>  isLeft(): this is Left&lt;never&gt; {<br>    return false;<br>  }<br>  isRight(): this is Right&lt;A&gt; {<br>    return true;<br>  }<br>}<br><br>type Either&lt;E, A&gt; = Left&lt;E&gt; | Right&lt;A&gt;;</pre><p><strong>Rewriting the Gunslinger Tale: A Code Haiku</strong></p><p>With the Either in hand, our gunslinger transforms into a haiku master:</p><pre>const result: Either&lt;Error, Data&gt; = riskyOperation();<br><br>if (result.isRight()) {<br>  console.log(result.value);<br>} else {<br>  console.error(result.value);<br>}</pre><p>Beautiful, isn’t it? Every step is crystal clear. We pattern-match against the Either, handling success and errors distinctly. Errors become tangible values, not shadowy bullets.</p><p><strong>The Oasis Blooms: Benefits of Functional Elegance</strong></p><p>This is just the beginning of our journey. Here’s why the functional approach reigns supreme:</p><ul><li><strong>Predictability:</strong> See the future! The Either’s type signature reveals what a function can return, guiding you on your coding path.</li><li><strong>Readability:</strong> No more squinting at cryptic errors. Functional code flows like a serene stream, clear and understandable.</li><li><strong>Testability:</strong> Errors become predictable guests, easily invited and analyzed for thorough testing.</li><li><strong>Composability:</strong> Chain functions like building blocks, creating modular and reusable code fortresses.</li></ul><p><strong>Beyond the Basics: Deeper into the Oasis</strong></p><p>Our oasis offers abundant resources to quench your coding thirst:</p><ul><li><strong>Advanced Patterns:</strong> Master techniques like Maybe and EitherT for nuanced error handling. Imagine these as specialized katanas, dealing with subtle threats with precision.</li><li><strong>Function Fusion:</strong> Chain functions like graceful sword strikes. Use map, flatMap, and filter to navigate the error landscape with elegance.</li><li><strong>Community Harmony:</strong> Share wisdom with fellow travelers! Explore libraries like fp-ts and Ramda, join online discussions, and learn from the masters.</li></ul><p><strong>Remember, functional error handling is not just a technique, it’s a philosophy.</strong> By embracing clarity, composability, and immutability, you craft code that shines like a polished blade. So, sharpen your functional sword, TypeScript warriors, and conquer the code desert with the power of the Either!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=018d2e13061c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Conquering NestJS Testing: From Tiny Gremlins to Robust Apps]]></title>
            <link>https://blog.stackademic.com/conquering-nestjs-testing-from-tiny-gremlins-to-robust-apps-3d1933a4978b?source=rss-94f6642dcc06------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d1933a4978b</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Oswaldo Oliveira]]></dc:creator>
            <pubDate>Wed, 13 Dec 2023 02:41:09 GMT</pubDate>
            <atom:updated>2023-12-21T01:20:43.762Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oI0pxMiDf81iJvL5" /><figcaption>Photo by <a href="https://unsplash.com/@flowforfrank?utm_source=medium&amp;utm_medium=referral">Ferenc Almasi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Building a NestJS application is thrilling, but without testing, it’s like flying blindfolded with a goblin on each wing. Fear not, brave developers, for this blog post equips you with the knowledge and tools to<strong> tame the bug gremlins</strong> and build <strong>robust, reliable NestJS applications.</strong></p><p><strong>Understanding the Testing Trinity:</strong></p><p>NestJS testing offers three tiers, each a powerful weapon against buggy monsters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Kqh4qnAb3I4uj7prK9WjtQ.gif" /></figure><p><strong>1. Unit Testing: Isolating the Gremlin Horde</strong></p><p>Imagine tiny, mischievous gremlins hiding within your code’s individual units (functions, classes). Unit tests are your nimble daggers, isolating and slaying these gremlins before they wreak havoc. Popular frameworks like Jest provide the perfect testing daggers, letting you write concise and effective tests for each unit.</p><p><strong>2. Integration Testing: United We Stand</strong></p><p>Picture these gremlins working together, causing chaos at the intersection of different code parts. Integration tests come to the rescue, forming a unified front to ensure smooth collaboration between these units. Think of them as a squad of knights, wielding shields and swords to defeat gremlin alliances.</p><p><strong>3. E2E Testing: The Final Showdown</strong></p><p>Now imagine the ultimate gremlin warlord, lurking within your entire application. Enter E2E testing, your mighty siege engine! Frameworks like Puppeteer act as your war machine, simulating real user interactions and storming the gremlin’s castle line by line.</p><p><strong>Choosing Your Weapons Wisely:</strong></p><p>Each testing type has its strengths and weaknesses:</p><ul><li>Unit tests: Fast, lightweight, ideal for early bug detection.</li><li>Integration tests: Cover broader interactions, but take longer to run.</li><li>E2E tests: Ultimate real-world confidence, but complex and time-consuming.</li></ul><p>The key is finding the right balance based on your needs and resources. Think of yourself as a seasoned warrior, strategically deploying each weapon to conquer the bug-infested landscape.</p><p><strong>Tips for Testing Heroes:</strong></p><ul><li>Start small and focus on critical areas. No need to test everything at once.</li><li>Write clear and concise tests. Avoid cryptic code that even Gandalf would struggle with.</li><li>Automate your tests! Continuous feedback is your best defense against surprise gremlin attacks.</li><li>Mock and stub dependencies. Isolate your units from external gremlins, like database calls.</li><li>Embrace refactoring. As your code evolves, so should your tests. Don’t let those gremlins exploit outdated defenses.</li></ul><p>Remember, testing is not a one-time quest. It’s an ongoing journey, a continuous battle against the ever-evolving gremlin hordes. But with these tools and tips, you’ll build NestJS applications that stand tall against any bug-based threat.</p><p><strong>Bonus Level: Deep Dives for Each Testing Type:</strong></p><p><strong>Unit Testing:</strong></p><ul><li>Popular frameworks: Jest, Mocha.</li><li>Testing strategies: Mocking dependencies, isolating functions, verifying outputs.</li><li>Example: Testing a service method that calculates discounts:</li></ul><pre>// discountService.test.ts<br><br>it(&#39;should calculate a 10% discount for VIP customers&#39;, () =&gt; {<br>  const discountService = new DiscountService();<br>  const price = 100;<br>  const customer = { isVip: true };<br><br>  const discountedPrice = discountService.calculateDiscount(price, customer);<br><br>  expect(discountedPrice).toBe(90);<br>});</pre><p><strong>Integration Testing:</strong></p><ul><li>Popular frameworks: Jest, TestingLibrary.</li><li>Testing strategies: Testing interactions between services, controllers, and repositories.</li><li>Example: Testing a controller that calls a service to fetch user data:</li></ul><pre>// usersController.test.ts<br><br>it(&#39;should return user details for a valid ID&#39;, async () =&gt; {<br>  const userService = mock&lt;UserService&gt;();<br>  const usersController = new UsersController(userService);<br><br>  const userId = 1;<br>  const mockUser = { id: userId, name: &#39;John Doe&#39; };<br>  userService.getUserById.mockResolvedValue(mockUser);<br><br>  const response = await usersController.getUserById(userId);<br><br>  expect(response.data).toEqual(mockUser);<br>});</pre><p><strong>E2E Testing:</strong></p><ul><li>Popular frameworks: Puppeteer, Cypress.</li><li>Testing strategies: Simulating user interactions like visiting pages, clicking buttons, and filling forms.</li><li>Example: Testing a login flow:</li></ul><pre>// login.test.ts<br><br>it(&#39;should allow users to login with valid credentials&#39;, async () =&gt; {<br>  const browser = await puppeteer.launch();<br>  const page = await browser.newPage();<br>  await page.goto(&#39;http://localhost:3000/login&#39;);<br>  <br>  await page.type(&#39;#username&#39;, &#39;johndoe&#39;);<br>  await page.type(&#39;#password&#39;, &#39;secret&#39;);<br>  await page.click(&#39;#loginButton&#39;);<br>  <br>  await page.waitForSelector(&#39;.dashboard&#39;);<br>  <br>  expect(page.url()).toBe(&#39;http://localhost:3000/dashboard&#39;);<br>  <br>  await browser.close();<br>});</pre><p><strong>Beyond the Basics:</strong></p><p>This blog post just scratches the surface of NestJS testing. Here are some advanced topics to explore:</p><ul><li>Testing asynchronous code: Learn how to handle promises and other asynchronous operations in your tests.</li><li>Mocking external dependencies: Master the art of mocking databases, APIs, and other external systems.</li><li>Testing error handling: Ensure your code gracefully handles unexpected situations.</li><li>Continuous integration and delivery (CI/CD): Automate your testing process and integrate it with your CI/CD pipeline.</li></ul><p>Remember, effective testing is an ongoing journey, not a one-time event. By mastering these testing techniques and adapting them to your specific needs, you can build NestJS applications that are robust, reliable, and free from those pesjky bug gremlins!</p><p>So, go forth and conquer the testing challenges, brave NestJS developers! Remember, with every slain gremlin, your application becomes one step closer to becoming a masterpiece.</p><p>I hope this additional information provides more depth and value to your blog post. Feel free to add your own personal insights, experiences, and examples to make it even more engaging for your readers!</p><h3>Stackademic</h3><p><em>Thank you for reading until the end. Before you go:</em></p><ul><li><em>Please consider </em><strong><em>clapping</em></strong><em> and </em><strong><em>following</em></strong><em> the writer! 👏</em></li><li><em>Follow us on </em><a href="https://twitter.com/stackademichq"><strong><em>Twitter(X)</em></strong></a><em>, </em><a href="https://www.linkedin.com/company/stackademic"><strong><em>LinkedIn</em></strong></a><em>, and </em><a href="https://www.youtube.com/c/stackademic"><strong><em>YouTube</em></strong></a><strong><em>.</em></strong></li><li><em>Visit </em><a href="http://stackademic.com/"><strong><em>Stackademic.com</em></strong></a><em> to find out more about how we are democratizing free programming education around the world.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d1933a4978b" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/conquering-nestjs-testing-from-tiny-gremlins-to-robust-apps-3d1933a4978b">Conquering NestJS Testing: From Tiny Gremlins to Robust Apps</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>