npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nestjs-boilerplate/auth-testing

v0.7.0

Published

NestJS Boilerplate is an open-source high-level framework for [NestJS](https://github.com/nestjs/nest) applications. It takes it up a notch by making it possible to solve repeatable tasks with less coding. It provides an architectural model based on Domai

Downloads

11

Readme

NestJS Boilerplate

NestJS Boilerplate is an open-source high-level framework for NestJS applications. It takes it up a notch by making it possible to solve repeatable tasks with less coding. It provides an architectural model based on Domain Driven Design and contains a variety of extra tools for a quick start developing NestJS applications. The NestJS Boilerplate aims to follow the principle of pluggable modules to extend functionality and less repeating common code from project to project. Inspired by Spring Framework, AspNet Boilerplate and Django.

Install

First

Install core package, testing package, user package, and auth package

Then

$ npm install @nestjs-boilerplate/auth-testing --save

Package description

Auth testing is a package that provides additional authentication tools for testing NestJS Boilerplate applications.

User factory

UserFactory class allows creating stub of the User entity.

import { UserFactory } from '@nestjs-boilerplate/auth-testing';

UserFactory.makeUser()
    .then(user => console.log(user));

Auth test utils

AuthTestUtils class contains a bunch of helpful methods for managing users, JWT tokens. TODO

| Method | Description | |----------------------------|-----------------------------------------------------------------------------------------| | saveUser | Saves provided user to the database | | makeAndSaveUser | Makes a stub of the user entity and saves it to the database. Returns the user instance | | clearAllUsers | Clear all users from the database | | generateJwtToken | Generates JWT token | | revokeJwtToken | Adds JWT token to a list of the blocked tokens | | getJwtAuthHeader | Returns authorization header value from JWT token | | generateResetPasswordToken | Generates reset password token for provided user |

import { TestingModuleBuilder } from '@nestjs/testing';
import { TestBootstrap } from '@nestjs-boilerplate/testing';
import { User } from '@nestjs-boilerplate/user';
import { UserFactory, AuthTestUtils } from '@nestjs-boilerplate/auth-testing';
import { AppModule } from './src/app.module';

describe('TestClass', () => {
    let app;
    let authTestUtils: AuthTestUtils;
    let user: User;

    beforeAll(async () => {
        app = await new TestBootstrap(AppModule)
            .startApplication();
        authTestUtils = new AuthTestUtils(app);
        user = await authTestUtils.makeAndSaveUser();
    });

    afterAll(async () => {
        await app.close();
    });

    afterEach(async () => {
        await authTestUtils.clearAllUsers();
    });
    
    // Your test cases...
});

Revoked tokens service

RevokedTokensService class extends BaseRevokedTokensService class and provides a mock implementation of the in-memory store of blocked tokens.

import { TestingModule, TestingModuleBuilder } from '@nestjs/testing';
import { TestBootstrap } from '@nestjs-boilerplate/testing';
import { BaseRevokedTokensService, RevokedTokensService } from '@nestjs-boilerplate/auth-testing';
import { AppModule } from './src/app.module';

describe('TestClass', () => {
    let revokedTokesService: BaseRevokedTokensService;
    let app;

    beforeAll(async () => {
        app = await new TestBootstrap(AppModule)
            .startApplication({
                onCreateTestingModule(builder: TestingModuleBuilder) {
                    return builder.overrideProvider(BaseRevokedTokensService)
                        .useValue(new RevokedTokensService());
                },
                onTestingModuleCreated: (testingModule: TestingModule) => {
                    revokedTokesService = app.get<BaseRevokedTokensService, RevokedTokensService>(
                        BaseRevokedTokensService,
                    );
                },
            });
    });

    afterAll(async () => {
        await app.close();
    });
    
    // Your test cases...
});

Keep in touch

Dmitry Kologrivko - [email protected]

License

MIT LICENSE