supertest#SuperAgentTest TypeScript Examples

The following examples show how to use supertest#SuperAgentTest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.handler.spec.ts    From node-experience with MIT License 6 votes vote down vote up
describe('Start Index Test', () =>
{
    let request: SuperAgentTest;
    let dbConnection: ICreateConnection;

    beforeAll(async() =>
    {
        const configServer = await initTestServer();

        request = configServer.request;
        dbConnection = configServer.dbConnection;
    });

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

    describe('#get', () =>
    {
        test('should have a status code of 200', async() =>
        {
            const response: any = await request.get('/');
            expect(response.statusCode).toStrictEqual(200);
        });
    });
});
Example #2
Source File: forgotPassword.handler.spec.ts    From node-experience with MIT License 5 votes vote down vote up
describe('Start ForgotPassword Test', () =>
{
    let request: SuperAgentTest;
    let dbConnection: ICreateConnection;
    let token: any = null;

    beforeAll(async() =>
    {
        jest.mock('../../Notification/Shared/EmailStrategy', () => jest.fn());
        // @ts-ignore
        EmailStrategy.send = jest.fn(() => async() => new Promise<boolean>((resolve) => resolve(true)));

        const configServer = await initTestServer();

        request = configServer.request;
        dbConnection = configServer.dbConnection;
    });

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

    describe('ForgotPassword Success', () =>
    {
        beforeAll(async() =>
        {
            const payload = {
                email: '[email protected]',
                password: '12345678'
            };

            const response: any = await request
                .post('/api/auth/login?provider=local')
                .set('Accept', 'application/json')
                .send(payload);

            const { body: { data } } = response;

            token = data.token;
        });

        test('ForgotPassword POST /', async() =>
        {
            const payload = {
                email: '[email protected]',
                password: '12345678'
            };

            const response: any = await request
                .post('/api/auth/forgot-password')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(201);
            expect(data.message).toStrictEqual('We\'ve sent you an email.');
        });
    });
});
Example #3
Source File: keepAlive.handler.spec.ts    From node-experience with MIT License 5 votes vote down vote up
describe('Start Keep Alive Test', () =>
{
    let request: SuperAgentTest;
    let dbConnection: ICreateConnection;
    let token: any = null;

    beforeAll(async() =>
    {
        const configServer = await initTestServer();

        request = configServer.request;
        dbConnection = configServer.dbConnection;
    });

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

    describe('Keep Alive Success', () =>
    {
        beforeAll(async() =>
        {
            const payload = {
                email: '[email protected]',
                password: '12345678'
            };

            const response: any = await request
                .post('/api/auth/login?provider=local')
                .set('Accept', 'application/json')
                .send(payload);

            const { body: { data } } = response;

            token = data.token;
        });

        test.skip('Keep Alive POST /', async() =>
        {
            const response: any = await request
                .post('/api/auth/keep-alive')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { metadata: { refreshToken } } } = response;

            expect(response.statusCode).toStrictEqual(201);

            token = refreshToken;
        });
    });
});
Example #4
Source File: whiteList.handler.spec.ts    From node-experience with MIT License 4 votes vote down vote up
describe('White list routes Test', () =>
{
    let request: SuperAgentTest;
    let dbConnection: ICreateConnection;

    beforeAll(async() =>
    {
        const configServer = await initTestServer();

        request = configServer.request;
        dbConnection = configServer.dbConnection;
    });

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

    describe('all', () =>
    {
        test('get', async() =>
        {
            const response: any = await request.get('/test/all/12345678');
            expect(response.statusCode).toStrictEqual(200);
        });

        test('post', async() =>
        {
            const response: any = await request.post('/test/all/hello/world');
            expect(response.statusCode).toStrictEqual(200);
        });

        test('put', async() =>
        {
            const response: any = await request.put('/test/all/numeric/123');
            expect(response.statusCode).toStrictEqual(200);
        });

        test('delete', async() =>
        {
            const response: any = await request.delete('/test/all/12345678/delete');
            expect(response.statusCode).toStrictEqual(200);
        });

        test('query', async() =>
        {
            const response: any = await request.get('/test/all/query?hola=mundo&hello=world');
            expect(response.statusCode).toStrictEqual(200);
        });
    });

    describe('equal', () =>
    {
        test('one', async() =>
        {
            const response: any = await request.get('/test/countries');
            expect(response.statusCode).toStrictEqual(200);
        });

        test('query', async() =>
        {
            const response: any = await request.get('/test/countries?status=true');
            expect(response.statusCode).toStrictEqual(200);
        });
    });

    describe('dynamic', () =>
    {
        test('equal', async() =>
        {
            const response: any = await request.get('/test/countries/12345678');
            expect(response.statusCode).toStrictEqual(200);
        });

        test('one', async() =>
        {
            const response: any = await request.get('/test/countries/12345678/states');
            expect(response.statusCode).toStrictEqual(200);
        });

        test('two', async() =>
        {
            const response: any = await request.get('/test/countries/12345678/states/12345678/cities');
            expect(response.statusCode).toStrictEqual(200);
        });

        test('query', async() =>
        {
            const response: any = await request.get('/test/countries/12345678/states?status=true');
            expect(response.statusCode).toStrictEqual(200);
        });
    });

    describe('untidy', () =>
    {
        describe('all', () =>
        {
            test('one', async() =>
            {
                const response: any = await request.get('/test/12345678/hello/all');
                expect(response.statusCode).toStrictEqual(403);
            });

            test('query', async() =>
            {
                const response: any = await request.get('/test/12345678/hello/all?status=true');
                expect(response.statusCode).toStrictEqual(403);
            });
        });

        describe('dynamic', () =>
        {
            test('one', async() =>
            {
                const response: any = await request.get('/test/cities/12345678/countries/12345678/states');
                expect(response.statusCode).toStrictEqual(403);
            });

            test('query', async() =>
            {
                const response: any = await request.get('/test/cities/12345678/countries/12345678/states?status=true');
                expect(response.statusCode).toStrictEqual(403);
            });
        });
    });
});
Example #5
Source File: login.handler.spec.ts    From node-experience with MIT License 4 votes vote down vote up
describe('Start Login Test', () =>
{
    let request: SuperAgentTest;
    let dbConnection: ICreateConnection;

    beforeAll(async() =>
    {
        const configServer = await initTestServer();

        request = configServer.request;
        dbConnection = configServer.dbConnection;
    });

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

    test('Login User Success', async() =>
    {
        const payload = {
            email: '[email protected]',
            password: '12345678'
        };

        const response: any = await request
            .post('/api/auth/login?provider=local')
            .set('Accept', 'application/json')
            .send(payload);

        const { body: { data } } = response;

        expect(response.statusCode).toStrictEqual(201);

        expect(data.user.email).toStrictEqual('[email protected]');
        expect(data.user.firstName).toStrictEqual('user');
    });

    test('Login SuperAdmin Success', async() =>
    {
        const payload = {
            email: '[email protected]',
            password: '12345678'
        };

        const response: any = await request
            .post('/api/auth/login?provider=local')
            .set('Accept', 'application/json')
            .send(payload);

        const { body: { data } } = response;

        expect(response.statusCode).toStrictEqual(201);

        expect(data.user.email).toStrictEqual('[email protected]');
        expect(data.user.firstName).toStrictEqual('Super');
    });

    test('Login User with Refresh Token', async() =>
    {
        const payload = {
            email: '[email protected]',
            password: '12345678'
        };

        const response: any = await request
            .post('/api/auth/login?provider=local')
            .set('Accept', 'application/json')
            .send(payload);

        const { body: { data } } = response;

        expect(response.statusCode).toStrictEqual(201);

        const loginCookie = response.header['set-cookie'];
        expect(loginCookie).toHaveLength(1);
        expect(loginCookie[0].split('=')[0]).toStrictEqual('refreshToken');
    });

    test('Login SuperAdmin Wrong Credentials', async() =>
    {
        const payload = {
            email: '[email protected]',
            password: '123456789'
        };

        const response: any = await request
            .post('/api/auth/login?provider=local')
            .set('Accept', 'application/json')
            .send(payload);

        const { body: { message } } = response;

        expect(response.statusCode).toStrictEqual(403);

        expect(message).toStrictEqual('Error credentials.');
    });

    test('Login Operator unverified', async() =>
    {
        const payload = {
            email: '[email protected]',
            password: '1234567901'
        };

        const response: any = await request
            .post('/api/auth/login?provider=local')
            .set('Accept', 'application/json')
            .send(payload);

        const { body: { message } } = response;

        expect(response.statusCode).toStrictEqual(403);

        expect(message).toStrictEqual('This user is not verified.');
    });

    test('Login Operator with Role Operator Enable False', async() =>
    {
        const payload = {
            email: '[email protected]',
            password: '123456790'
        };

        const response: any = await request
            .post('/api/auth/login?provider=local')
            .set('Accept', 'application/json')
            .send(payload);

        const { body: { message } } = response;

        expect(response.statusCode).toStrictEqual(403);

        expect(message).toStrictEqual('Your role is disable.');
    });
});
Example #6
Source File: permission.handler.spec.ts    From node-experience with MIT License 4 votes vote down vote up
describe('Start Permission Test', () =>
{
    let request: SuperAgentTest;
    let dbConnection: ICreateConnection;
    let token: any = null;

    beforeAll(async() =>
    {
        const configServer = await initTestServer();

        request = configServer.request;
        dbConnection = configServer.dbConnection;
    });

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

    describe('', () =>
    {
        beforeAll(async() =>
        {
            const payload = {
                email: '[email protected]',
                password: '12345678'
            };

            const response: any = await request
                .post('/api/auth/login?provider=local')
                .set('Accept', 'application/json')
                .send(payload);

            const { body: { data } } = response;

            token = data.token;
        });

        test('Get Permissions', async() =>
        {
            const response: IPermissionsResponse = await request
                .get('/api/auth/permissions')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(200);

            const keepAlive = data.some(({ group, permissions }) => group === 'USERS' && permissions.some((permission) => permission === 'usersSave'));

            expect(keepAlive).toStrictEqual(true);
        });

        test('Resource Not found', async() =>
        {
            const response: any = await request
                .get('/api/auth/notfound')
                .set('Authorization', `Bearer ${token}`)
                .set('Accept', 'application/json')
                .send();

            const { body: { message } } = response;

            expect(response.statusCode).toStrictEqual(404);
            expect(message).toStrictEqual('Route not found.');
        });

        test('Not authorized', async() =>
        {
            const response: any = await request
                .get('/api/auth/permissions')
                .set('Accept', 'application/json')
                .send();

            const { body: { message } } = response;

            expect(response.statusCode).toStrictEqual(403);

            expect(message).toStrictEqual('Invalid token.');
        });
    });
});
Example #7
Source File: file.handler.spec.ts    From node-experience with MIT License 4 votes vote down vote up
describe('Start File Test', () =>
{
    let request: SuperAgentTest;
    let dbConnection: ICreateConnection;
    let token: string = null;
    let file_id = '';

    beforeAll(async() =>
    {
        const configServer = await initTestServer();

        request = configServer.request;
        dbConnection = configServer.dbConnection;

        jest.spyOn(FilesystemFactory, 'create').mockImplementation(() => new MockMinioStrategy());
    });

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

    describe('File Success', () =>
    {
        beforeAll(async() =>
        {
            const payload = {
                email: '[email protected]',
                password: '12345678'
            };

            const response: ILoginResponse = await request
                .post('/api/auth/login?provider=local')
                .set('Accept', 'application/json')
                .send(payload);

            const { body: { data } } = response;

            token = data.token;
        });

        test('Add File /files/base64', async() =>
        {
            const response: IFileResponse = await request
                .post('/api/files/base64')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(UploadFileBase64);

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(201);

            file_id = data.id;
        });

        test('Get File /files/metadata/:id', async() =>
        {
            const payload = {
                originalName: 'photo.jpg',
                extension: 'jpg',
                mimeType: 'image/jpeg',
                isPublic: false
            };

            const response: IFileResponse = await request
                .get(`/api/files/metadata/${file_id}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(200);
        });

        // test('Get File /files/:id', async () =>
        // {
        //     const response: any = await request
        //         .get(`/api/files/${fileId}`)
        //         .set('Accept', 'application/json')
        //         .set('Authorization', `Bearer ${token}`)
        //         .send();
        //
        //     const {body: {status, statusCode}} = response;
        //
        //     expect(response.statusCode).toStrictEqual(200);
        //     expect(status).toStrictEqual('success');
        //     expect(statusCode).toStrictEqual('HTTP_OK');
        //
        // });
        //
        // test('Update Item /items/:id', async () =>
        // {
        //     const payload = {
        //         name: 'Item 1 updateRep',
        //         type: 11
        //     };
        //
        //     const response: any = await request
        //         .put(`/api/items/${fileId}`)
        //         .set('Accept', 'application/json')
        //         .set('Authorization', `Bearer ${token}`)
        //         .send(payload);
        //
        //     const {body: {data}} = response;
        //
        //     expect(response.statusCode).toStrictEqual(201);
        //     expect(status).toStrictEqual('success');
        //     expect(statusCode).toStrictEqual('HTTP_CREATED');
        //
        //     expect(data.name).toStrictEqual(payload.name);
        //     expect(data.type).toStrictEqual(payload.type);
        //
        // });
        //
        // test('Delete Item /items/:id', async () =>
        // {
        //     const payload = {
        //         name: 'Item 13 for delete',
        //         type: 13
        //     };
        //
        //     const createResponse: any = await request
        //         .post('/api/items')
        //         .set('Accept', 'application/json')
        //         .set('Authorization', `Bearer ${token}`)
        //         .send(payload);
        //
        //     deleteResponse = await request
        //         .delete(`/api/items/${createResponse.body.data.id}`)
        //         .set('Accept', 'application/json')
        //         .set('Authorization', `Bearer ${createResponse.body.metadata.refreshToken}`)
        //         .send();
        //
        //     const {body: {data}} = deleteResponse;
        //
        //     expect(deleteResponse.statusCode).toStrictEqual(200);
        //     expect(status).toStrictEqual('success');
        //     expect(statusCode).toStrictEqual('HTTP_OK');
        //
        //     expect(data.name).toStrictEqual(payload.name);
        //     expect(data.type).toStrictEqual(payload.type);
        //
        // });
        //
        // test('Get Items /items', async () =>
        // {
        //
        //     const response: any = await request
        //         .get('/api/items?pagination[limit]=5&pagination[offset]=0')
        //         .set('Accept', 'application/json')
        //         .set('Authorization', `Bearer ${token}`)
        //         .send();
        //
        //     const {body: {data, pagination}} = response;
        //
        //     expect(response.statusCode).toStrictEqual(200);
        //     expect(status).toStrictEqual('success');
        //     expect(statusCode).toStrictEqual('HTTP_OK');
        //
        //     expect(data.length).toStrictEqual(5);
        //     expect(pagination.total).toStrictEqual(5);
        //     expect(pagination.currentUrl).toContain('/api/items?pagination[limit]=5&pagination[offset]=0');
        //     expect(pagination.nextUrl).toContain('/api/items?pagination[limit]=5&pagination[offset]=5');
        //
        // });
        //
        // test('Get Items /items without pagination', async () =>
        // {
        //
        //     const response: any = await request
        //         .get('/api/items')
        //         .set('Accept', 'application/json')
        //         .set('Authorization', `Bearer ${token}`)
        //         .send();
        //
        //     const {body: {data, pagination}} = response;
        //
        //     expect(response.statusCode).toStrictEqual(200);
        //     expect(status).toStrictEqual('success');
        //     expect(statusCode).toStrictEqual('HTTP_OK');
        //
        //     expect(data.length).toStrictEqual(11);
        //     expect(pagination).not.toBeDefined();
        //
        // });
        //
        // test('Get Items /items with Filter Type', async () =>
        // {
        //
        //     const response: any = await request
        //         .get('/api/items?pagination[limit]=20&pagination[offset]=0&filter[type]=11')
        //         .set('Accept', 'application/json')
        //         .set('Authorization', `Bearer ${token}`)
        //         .send();
        //
        //     const {body: {data, pagination}} = response;
        //
        //     expect(response.statusCode).toStrictEqual(200);
        //     expect(status).toStrictEqual('success');
        //     expect(statusCode).toStrictEqual('HTTP_OK');
        //
        //     expect(data.length).toStrictEqual(1);
        //     expect(pagination.total).toStrictEqual(1);
        //
        //     expect(data[0].type).toStrictEqual(11);
        //
        // });
        //
        // test('Get Items /items with Sort Desc Type', async () =>
        // {
        //
        //     const response: any = await request
        //         .get('/api/items?pagination[limit]=20&pagination[offset]=0&sort[type]=desc')
        //         .set('Accept', 'application/json')
        //         .set('Authorization', `Bearer ${token}`)
        //         .send();
        //
        //     const {body: {data: [item1, item2]}} = response;
        //
        //     expect(response.statusCode).toStrictEqual(200);
        //     expect(status).toStrictEqual('success');
        //     expect(statusCode).toStrictEqual('HTTP_OK');
        //
        //     expect(item1.type).toBeGreaterThanOrEqual(item2.type);
        //
        // });
    });

    // describe('Item Fails', () =>
    // {
    //     beforeAll(async() =>
    //     {
    //         const payload = {
    //             email: '[email protected]',
    //             password: '12345678'
    //         };
    //
    //         const response: any = await request
    //             .post('/api/auth/login?provider=local')
    //             .set('Accept', 'application/json')
    //             .send(payload);
    //
    //         const {body: {data}} = response;
    //
    //         token = data.token;
    //
    //     });
    //
    //     test('Add File /files/base64', async () =>
    //     {
    //         const response: any = await request
    //             .post('/api/items')
    //             .set('Accept', 'application/json')
    //             .set('Authorization', `Bearer ${token}`)
    //             .send(UploadFileBase64);
    //
    //         const {body: {message, errors: [error]}} = response;
    //
    //         expect(response.statusCode).toStrictEqual(422);
    //         expect(status).toStrictEqual('error');
    //         expect(statusCode).toStrictEqual('HTTP_UNPROCESSABLE_ENTITY');
    //         expect(message).toStrictEqual('Failed Request.');
    //
    //         expect(error.property).toStrictEqual('type');
    //         expect(error.constraints.isInt).toStrictEqual('type must be an integer number');
    //
    //     });
    //
    //     test('Get Item /items/:id', async () =>
    //     {
    //
    //         const response: any = await request
    //             .get(`/api/items/${fileId}dasdasda123`)
    //             .set('Accept', 'application/json')
    //             .set('Authorization', `Bearer ${token}`)
    //             .send();
    //
    //         const {body: {message, errors: [error]}} = response;
    //
    //         expect(response.statusCode).toStrictEqual(422);
    //         expect(status).toStrictEqual('error');
    //         expect(statusCode).toStrictEqual('HTTP_UNPROCESSABLE_ENTITY');
    //         expect(message).toStrictEqual('Failed Request.');
    //
    //         expect(error.property).toStrictEqual('id');
    //         expect(error.constraints.isUuid).toBeDefined();
    //         expect(error.constraints.isUuid).toStrictEqual('id must be an UUID');
    //
    //     });
    //
    //     test('Update Item /items/:id', async () =>
    //     {
    //         const payload = {
    //             name: 11,
    //             type: 'asdasd'
    //         };
    //
    //         const response: any = await request
    //             .put(`/api/items/${fileId}`)
    //             .set('Accept', 'application/json')
    //             .set('Authorization', `Bearer ${token}`)
    //             .send(payload);
    //
    //         const {body: {message, errors: [errorName, errorType]}} = response;
    //
    //         expect(response.statusCode).toStrictEqual(422);
    //         expect(status).toStrictEqual('error');
    //         expect(statusCode).toStrictEqual('HTTP_UNPROCESSABLE_ENTITY');
    //         expect(message).toStrictEqual('Failed Request.');
    //
    //         expect(errorName.property).toStrictEqual('name');
    //         expect(errorName.constraints.isString).toBeDefined();
    //         expect(errorName.constraints.isString).toStrictEqual('name must be a string');
    //
    //         expect(errorType.property).toStrictEqual('type');
    //         expect(errorType.constraints.isInt).toBeDefined();
    //         expect(errorType.constraints.isInt).toStrictEqual('type must be an integer number');
    //
    //     });
    //
    //     test('Delete Item error /items/:id', async () =>
    //     {
    //
    //         const deleteErrorResponse: any = await request
    //             .delete(`/api/items/${deleteResponse.body.data.id}`)
    //             .set('Accept', 'application/json')
    //             .set('Authorization', `Bearer ${token}`)
    //             .send();
    //
    //         const {body: {message}} = deleteErrorResponse;
    //
    //         expect(deleteErrorResponse.statusCode).toStrictEqual(400);
    //         expect(status).toStrictEqual('error');
    //         expect(statusCode).toStrictEqual('HTTP_BAD_REQUEST');
    //         expect(message).toStrictEqual('Item not found.');
    //
    //     });
    // });
});
Example #8
Source File: item.handler.spec.ts    From node-experience with MIT License 4 votes vote down vote up
describe('Start Item Test', () =>
{
    let request: SuperAgentTest;
    let dbConnection: ICreateConnection;
    let token: string = null;
    let itemId = '';
    let deleteResponse: any = null;

    beforeAll(async() =>
    {
        const configServer = await initTestServer();

        request = configServer.request;
        dbConnection = configServer.dbConnection;
    });

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

    describe('Item Success', () =>
    {
        beforeAll(async() =>
        {
            const payload = {
                email: '[email protected]',
                password: '12345678'
            };

            const response: ILoginResponse = await request
                .post('/api/auth/login?provider=local')
                .set('Accept', 'application/json')
                .send(payload);

            const { body: { data } } = response;

            token = data.token;
        });

        test('Add Item /items', async() =>
        {
            const payload = {
                name: 'Item 1',
                type: 10
            };

            const response: IItemResponse = await request
                .post('/api/items')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(201);

            itemId = data.id;
        });

        test('Get Item /items/:id', async() =>
        {
            const payload = {
                name: 'Item 1',
                type: 10
            };

            const response: IItemResponse = await request
                .get(`/api/items/${itemId}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(data.name).toStrictEqual(payload.name);
            expect(data.type).toStrictEqual(payload.type);
        });

        test('Update Item /items/:id', async() =>
        {
            const payload = {
                name: 'Item 1 update',
                type: 11
            };

            const response: IItemResponse = await request
                .put(`/api/items/${itemId}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(201);
        });

        test('Delete Item /items/:id', async() =>
        {
            const payload = {
                name: 'Item 13 for delete',
                type: 13
            };

            const createResponse: IItemResponse = await request
                .post('/api/items')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            deleteResponse = await request
                .delete(`/api/items/${createResponse.body.data.id}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data } } = deleteResponse;

            expect(deleteResponse.statusCode).toStrictEqual(200);

            expect(data.name).toStrictEqual(payload.name);
            expect(data.type).toStrictEqual(payload.type);
        });

        test('Get Items /items', async() =>
        {
            const config = MainConfig.getInstance();

            const response: IListItemsResponse = await request
                .get('/api/items?pagination[offset]=0&pagination[limit]=5')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data, pagination } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(data.length).toStrictEqual(5);
            expect(pagination.total).toStrictEqual(11);
            expect(pagination.perPage).toStrictEqual(5);
            expect(pagination.currentPage).toStrictEqual(1);
            expect(pagination.lastPage).toStrictEqual(3);
            expect(pagination.from).toStrictEqual(0);
            expect(pagination.to).toStrictEqual(5);
            expect(pagination.path).toContain(config.getConfig().url.urlApi);
            expect(pagination.firstUrl).toContain('/api/items?pagination[offset]=0&pagination[limit]=5');
            expect(pagination.lastUrl).toContain('/api/items?pagination[offset]=10&pagination[limit]=5');
            expect(pagination.nextUrl).toContain('/api/items?pagination[offset]=5&pagination[limit]=5');
            expect(pagination.prevUrl).toStrictEqual(null);
            expect(pagination.currentUrl).toContain('/api/items?pagination[offset]=0&pagination[limit]=5');
        });

        test('Get Items /items without pagination', async() =>
        {
            const response: IListItemsResponse = await request
                .get('/api/items')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data, pagination } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(data.length).toStrictEqual(11);
            expect(pagination).not.toBeDefined();
        });

        test('Get Items /items with Filter Type', async() =>
        {
            const response: IListItemsResponse = await request
                .get('/api/items?pagination[limit]=20&pagination[offset]=0&filter[type]=11')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data, pagination } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(data.length).toStrictEqual(1);
            expect(pagination.total).toStrictEqual(1);

            expect(data[0].type).toStrictEqual(11);
        });

        test('Get Items /items with Sort Desc Type', async() =>
        {
            const response: IListItemsResponse = await request
                .get('/api/items?pagination[limit]=20&pagination[offset]=0&sort[type]=desc')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data: [item1, item2] } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(item1.type).toBeGreaterThanOrEqual(item2.type);
        });
    });

    describe('Item Fails', () =>
    {
        beforeAll(async() =>
        {
            const payload = {
                email: '[email protected]',
                password: '12345678'
            };

            const response: ILoginResponse = await request
                .post('/api/auth/login?provider=local')
                .set('Accept', 'application/json')
                .send(payload);

            const { body: { data } } = response;

            token = data.token;
        });

        test('Add Item /items', async() =>
        {
            const payload = {
                name: 'Item 2',
                type: 'Item 1'
            };

            const response: IItemResponse = await request
                .post('/api/items')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { message, errors: [error] } } = response;

            expect(response.statusCode).toStrictEqual(422);
            expect(message).toStrictEqual('Failed Request.');

            expect(error.property).toStrictEqual('type');
            expect(error.constraints.isInt).toStrictEqual('type must be an integer number');
        });

        test('Get Item /items/:id', async() =>
        {
            const response: IItemResponse = await request
                .get(`/api/items/${itemId}dasdasda123`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { message, errors: [error] } } = response;

            expect(response.statusCode).toStrictEqual(422);
            expect(message).toStrictEqual('Failed Request.');

            expect(error.property).toStrictEqual('id');
            expect(error.constraints.isUuid).toBeDefined();
            expect(error.constraints.isUuid).toStrictEqual('id must be a UUID');
        });

        test('Update Item /items/:id', async() =>
        {
            const payload = {
                name: 11,
                type: 'asdasd'
            };

            const response: IItemResponse = await request
                .put(`/api/items/${itemId}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { message, errors: [errorName, errorType] } } = response;

            expect(response.statusCode).toStrictEqual(422);
            expect(message).toStrictEqual('Failed Request.');

            expect(errorName.property).toStrictEqual('name');
            expect(errorName.constraints.isString).toBeDefined();
            expect(errorName.constraints.isString).toStrictEqual('name must be a string');

            expect(errorType.property).toStrictEqual('type');
            expect(errorType.constraints.isInt).toBeDefined();
            expect(errorType.constraints.isInt).toStrictEqual('type must be an integer number');
        });

        test('Delete Item error /items/:id', async() =>
        {
            const deleteErrorResponse: IItemResponse = await request
                .delete(`/api/items/${deleteResponse.body.data.id}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { message } } = deleteErrorResponse;

            expect(deleteErrorResponse.statusCode).toStrictEqual(400);
            expect(message).toStrictEqual('Item not found.');
        });
    });
});
Example #9
Source File: role.handler.spec.ts    From node-experience with MIT License 4 votes vote down vote up
describe('Start Role Test', () =>
{
    let request: SuperAgentTest;
    let dbConnection: ICreateConnection;
    let token: string = null;
    let roleId = '';
    let deleteResponse: any = null;

    beforeAll(async() =>
    {
        const configServer = await initTestServer();

        request = configServer.request;
        dbConnection = configServer.dbConnection;
    });

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

    describe('Role Success', () =>
    {
        beforeAll(async() =>
        {
            const payload = {
                email: '[email protected]',
                password: '12345678'
            };

            const response: ILoginResponse = await request
                .post('/api/auth/login?provider=local')
                .set('Accept', 'application/json')
                .send(payload);

            const { body: { data } } = response;

            token = data.token;
        });

        test('Add Role without enable property /roles', async() =>
        {
            const payload: any = {
                name: 'Role1 Test',
                slug: 'role1test',
                permissions: []
            };

            const response: IRoleResponse = await request
                .post('/api/roles')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(201);

            roleId = data.id;
        });

        test('Add Role with enable property /roles', async() =>
        {
            const payload: any = {
                name: 'Role2 Test',
                slug: 'role2test',
                permissions: [],
                enable: false
            };

            const response: IRoleResponse = await request
                .post('/api/roles')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(201);

            roleId = data.id;
        });

        test('Add Role with permissions property /roles', async() =>
        {
            const payload: any = {
                name: 'Role3 Test',
                slug: 'role3test',
                permissions: ['usersSave'],
                enable: true
            };

            const response: IRoleResponse = await request
                .post('/api/roles')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(201);

            roleId = data.id;
        });

        test('Get Role /roles/:id', async() =>
        {
            const payload: any = {
                name: 'Role3 Test',
                slug: 'role3test',
                permissions: ['usersSave'],
                enable: true
            };

            const response: IRoleResponse = await request
                .get(`/api/roles/${roleId}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(data.name).toStrictEqual(payload.name);
            expect(data.slug).toStrictEqual(payload.slug);
            expect(data.permissions).toStrictEqual(payload.permissions);
            expect(data.enable).toStrictEqual(payload.enable);
        });

        test('Update Role /roles/:id', async() =>
        {
            const payload: any = {
                name: 'Role3 Test Update',
                slug: 'role3testupdate',
                permissions: ['usersDelete'],
                enable: false
            };

            const response: IRoleResponse = await request
                .put(`/api/roles/${roleId}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            expect(response.statusCode).toStrictEqual(201);
        });

        test('Delete Role /roles/:id', async() =>
        {
            const payload: any = {
                name: 'Role4 Test',
                slug: 'role4test',
                permissions: ['usersSave'],
                enable: true
            };

            const createResponse: IRoleResponse = await request
                .post('/api/roles')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            deleteResponse = await request
                .delete(`/api/roles/${createResponse.body.data.id}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data } } = deleteResponse;

            expect(deleteResponse.statusCode).toStrictEqual(201);

            expect(data.name).toStrictEqual(payload.name);
            expect(data.slug).toStrictEqual(payload.slug);
            expect(data.permissions).toStrictEqual(payload.permissions);
            expect(data.enable).toStrictEqual(payload.enable);
        });

        test('Get Roles /roles', async() =>
        {
            const config = MainConfig.getInstance();

            const response: IListRolesResponse = await request
                .get('/api/roles?pagination[offset]=0&pagination[limit]=5')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data, pagination } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(data.length).toStrictEqual(5);
            expect(pagination.total).toStrictEqual(7);
            expect(pagination.perPage).toStrictEqual(5);
            expect(pagination.currentPage).toStrictEqual(1);
            expect(pagination.lastPage).toStrictEqual(2);
            expect(pagination.from).toStrictEqual(0);
            expect(pagination.to).toStrictEqual(5);
            expect(pagination.path).toContain(config.getConfig().url.urlApi);
            expect(pagination.firstUrl).toContain('/api/roles?pagination[offset]=0&pagination[limit]=5');
            expect(pagination.lastUrl).toContain('/api/roles?pagination[offset]=5&pagination[limit]=5');
            expect(pagination.nextUrl).toContain('/api/roles?pagination[offset]=5&pagination[limit]=5');
            expect(pagination.prevUrl).toStrictEqual(null);
            expect(pagination.currentUrl).toContain('/api/roles?pagination[offset]=0&pagination[limit]=5');
        });

        test('Get Roles /roles without pagination', async() =>
        {
            const response: IListRolesResponse = await request
                .get('/api/roles')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data, pagination } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(data.length).toStrictEqual(7);
            expect(pagination).not.toBeDefined();
        });

        test('Get Roles /roles with Filter Type', async() =>
        {
            const response: IListRolesResponse = await request
                .get('/api/roles?pagination[limit]=20&pagination[offset]=0&filter[slug]=admin')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data, pagination } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(data.length).toStrictEqual(1);
            expect(pagination.total).toStrictEqual(1);
        });

        test('Get Roles /roles with Sort Desc Type', async() =>
        {
            const response: IListRolesResponse = await request
                .get('/api/roles?pagination[limit]=20&pagination[offset]=0&sort[slug]=desc')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data: [role1, role2] } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(role1.slug).toStrictEqual('superAdmin');
            expect(role2.slug).toStrictEqual('role3testupdate');
        });

        test('Sync roles permissions /sync-roles-permissions', async() =>
        {
            const response: any = await request
                .post('/api/auth/sync-roles-permissions')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(201);
            expect(data.message).toStrictEqual('Sync Successfully');
        });
    });

    describe('Role Fails', () =>
    {
        beforeAll(async() =>
        {
            const payload = {
                email: '[email protected]',
                password: '12345678'
            };

            const response: ILoginResponse = await request
                .post('/api/auth/login?provider=local')
                .set('Accept', 'application/json')
                .send(payload);

            const { body: { data } } = response;

            token = data.token;
        });

        test('Add Role /roles', async() =>
        {
            const payload = {
                firstName: 'Role 2'
            };

            const response: IRoleResponse = await request
                .post('/api/roles')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { message, errors: [error] } } = response;

            expect(response.statusCode).toStrictEqual(422);
            expect(message).toStrictEqual('Failed Request.');

            expect(error.property).toStrictEqual('name');
            expect(error.constraints.isString).toBeDefined();
            expect(error.constraints.isString).toStrictEqual('name must be a string');
        });

        test('Get Role /roles/:id', async() =>
        {
            const response: IRoleResponse = await request
                .get(`/api/roles/${roleId}dasdasda123`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { message, errors: [error] } } = response;

            expect(response.statusCode).toStrictEqual(422);
            expect(message).toStrictEqual('Failed Request.');

            expect(error.property).toStrictEqual('id');
            expect(error.constraints.isUuid).toBeDefined();
            expect(error.constraints.isUuid).toStrictEqual('id must be a UUID');
        });

        test('Update Role /roles/:id', async() =>
        {
            const payload: any = {
                name: 150,
                slug: 'role3testupdate',
                enable: 'false'
            };

            const response: IRoleResponse = await request
                .put(`/api/roles/${roleId}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { message, errors: [error1, error2] } } = response;

            expect(response.statusCode).toStrictEqual(422);
            expect(message).toStrictEqual('Failed Request.');

            expect(error1.property).toStrictEqual('permissions');
            expect(error1.constraints.isArray).toBeDefined();
            expect(error1.constraints.isArray).toStrictEqual('permissions must be an array');

            expect(error2.property).toStrictEqual('name');
            expect(error2.constraints.isString).toBeDefined();
            expect(error2.constraints.isString).toStrictEqual('name must be a string');
        });

        test('Delete Role error /roles/:id', async() =>
        {
            const deleteErrorResponse: IRoleResponse = await request
                .delete(`/api/roles/${deleteResponse.body.data.id}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { message } } = deleteErrorResponse;

            expect(deleteErrorResponse.statusCode).toStrictEqual(400);
            expect(message).toStrictEqual('Role not found.');
        });
    });
});
Example #10
Source File: user.handler.spec.ts    From node-experience with MIT License 4 votes vote down vote up
describe('Start User Test', () =>
{
    let request: SuperAgentTest;
    let dbConnection: ICreateConnection;
    let token: string = null;
    let userId = '';
    let deleteResponse: any = null;

    beforeAll(async() =>
    {
        const configServer = await initTestServer();

        request = configServer.request;
        dbConnection = configServer.dbConnection;
    });

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

    describe('User Success', () =>
    {
        beforeAll(async() =>
        {
            const payload = {
                email: '[email protected]',
                password: '12345678'
            };

            const response: ILoginResponse = await request
                .post('/api/auth/login?provider=local')
                .set('Accept', 'application/json')
                .send(payload);

            const { body: { data } } = response;

            token = data.token;
        });

        test('Add User without enable property /users', async() =>
        {
            const payload: any = {
                firstName: 'Jhon',
                lastName: 'Doe',
                email: '[email protected]',
                birthday: '04/08/1991',
                documentType: 'dni',
                documentNumber: '35319112',
                gender: 'male',
                phone: '2234456999',
                country: 'AR',
                address: 'Norway 123',
                password: '12345678',
                passwordConfirmation: '12345678',
                permissions: []
            };

            const response: IUserResponse = await request
                .post('/api/users')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(201);

            userId = data.id;
        });

        test('Add User with enable property /users', async() =>
        {
            const payload: any = {
                firstName: 'Jhon',
                lastName: 'Doe',
                email: '[email protected]',
                birthday: '04/08/1992',
                documentType: 'dni',
                documentNumber: '35319321',
                gender: 'male',
                phone: '2234456999',
                country: 'AR',
                address: 'Norway 123',
                password: '12345678',
                passwordConfirmation: '12345678',
                enable: false,
                permissions: []
            };

            const response: IUserResponse = await request
                .post('/api/users')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(201);

            userId = data.id;
        });

        test('Get User /users/:id', async() =>
        {
            const payload: any = {
                firstName: 'Jhon',
                lastName: 'Doe',
                email: '[email protected]',
                password: '12345678',
                password_confirmation: '12345678',
                permissions: []
            };

            const response: IUserResponse = await request
                .get(`/api/users/${userId}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(data.firstName).toStrictEqual(payload.firstName);
            expect(data.email).toStrictEqual(payload.email);
        });

        test('Update User /users/:id', async() =>
        {
            const payload: any = {
                firstName: 'Jhon Update',
                lastName: 'Doe Update',
                email: '[email protected]',
                birthday: '04/08/1991',
                documentType: 'dni',
                documentNumber: '35319131',
                gender: 'female',
                phone: '22344569121',
                country: 'UR',
                address: 'Norway 124',
                enable: false,
                permissions: []
            };

            const response: IUserResponse = await request
                .put(`/api/users/${userId}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { data } } = response;

            expect(response.statusCode).toStrictEqual(201);
        });

        test('Change my Password /users/change-my-password', async() =>
        {
            let payload: any = {
                currentPassword: '12345678',
                password: '123456789',
                passwordConfirmation: '123456789'
            };

            let response: any = await request
                .post('/api/users/change-my-password')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            expect(response.statusCode).toStrictEqual(201);

            payload = {
                email: 'user@node.com',
                password: '123456789'
            };

            response = await request
                .post('/api/auth/login?provider=local')
                .set('Accept', 'application/json')
                .send(payload);

            expect(response.statusCode).toStrictEqual(201);

            token = response.body.data.token;
        });

        test('Delete User /users/:id', async() =>
        {
            const payload: any = {
                email: 'user2@delete.com',
                firstName: 'Jhon for delete',
                lastName: 'Doe Update',
                birthday: '04/08/1992',
                documentType: 'dni',
                documentNumber: '25319112',
                gender: 'male',
                phone: '2234456999',
                country: 'AR',
                address: 'Norway 126',
                password: '12345678',
                enable: false,
                passwordConfirmation: '12345678',
                permissions: []
            };

            const createResponse: IUserResponse = await request
                .post('/api/users')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            deleteResponse = await request
                .delete(`/api/users/${createResponse.body.data.id}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data } } = deleteResponse;

            expect(deleteResponse.statusCode).toStrictEqual(200);

            expect(data.firstName).toStrictEqual(payload.firstName);
            expect(data.email).toStrictEqual(payload.email);
        });

        test('Get Users /users', async() =>
        {
            const config = MainConfig.getInstance();

            const response: IListUsersResponse = await request
                .get('/api/users?pagination[offset]=0&pagination[limit]=5')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { pagination } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(pagination.offset).toStrictEqual(0);
            expect(pagination.limit).toStrictEqual(5);
            expect(pagination.perPage).toStrictEqual(5);
            expect(pagination.currentPage).toStrictEqual(1);
            expect(pagination.lastPage).toStrictEqual(2);
            expect(pagination.from).toStrictEqual(0);
            expect(pagination.to).toStrictEqual(5);
            expect(pagination.path).toContain(config.getConfig().url.urlApi);
            expect(pagination.firstUrl).toContain('/api/users?pagination[offset]=0&pagination[limit]=5');
            expect(pagination.lastUrl).toContain('/api/users?pagination[offset]=5&pagination[limit]=5');
            expect(pagination.nextUrl).toContain('/api/users?pagination[offset]=5&pagination[limit]=5');
            expect(pagination.prevUrl).toStrictEqual(null);
            expect(pagination.currentUrl).toContain('/api/users?pagination[offset]=0&pagination[limit]=5');
        });

        test('Get Users /users without pagination', async() =>
        {
            const response: IListUsersResponse = await request
                .get('/api/users')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { pagination } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(pagination).not.toBeDefined();
        });

        test('Get Users /users with Filter Type', async() =>
        {
            const response: IListUsersResponse = await request
                .get('/api/users?pagination[limit]=20&pagination[offset]=0&filter[email][email protected]')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data, pagination } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(data.length).toStrictEqual(1);
            expect(pagination.total).toStrictEqual(1);
        });

        test('Get Users /users with Sort Desc Type', async() =>
        {
            const response: IListUsersResponse = await request
                .get('/api/users?pagination[limit]=20&pagination[offset]=0&sort[email]=desc')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { data: [user1, user2] } } = response;

            expect(response.statusCode).toStrictEqual(200);

            expect(user1.email).toStrictEqual('[email protected]');
            expect(user2.email).toStrictEqual('[email protected]');
        });
    });

    describe('User Fails', () =>
    {
        beforeAll(async() =>
        {
            const payload = {
                email: '[email protected]',
                password: '123456789'
            };

            const response: ILoginResponse = await request
                .post('/api/auth/login?provider=local')
                .set('Accept', 'application/json')
                .send(payload);

            const { body: { data } } = response;

            token = data.token;
        });

        test('Add User /users', async() =>
        {
            const payload = {
                name: 'User 2',
                type: 'User 1'
            };

            const response: IUserResponse = await request
                .post('/api/users')
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { message, errors: [error] } } = response;

            expect(response.statusCode).toStrictEqual(422);
            expect(message).toStrictEqual('Failed Request.');

            expect(error.property).toStrictEqual('permissions');
            expect(error.constraints.isString).toBeDefined();
            expect(error.constraints.isString).toStrictEqual('each value in permissions must be a string');
        });

        test('Get User /users/:id', async() =>
        {
            const response: IUserResponse = await request
                .get(`/api/users/${userId}dasdasda123`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { message, errors: [error] } } = response;

            expect(response.statusCode).toStrictEqual(422);
            expect(message).toStrictEqual('Failed Request.');

            expect(error.property).toStrictEqual('id');
            expect(error.constraints.isUuid).toBeDefined();
            expect(error.constraints.isUuid).toStrictEqual('id must be a UUID');
        });

        test('Update User /users/:id', async() =>
        {
            const payload = {
                email: '[email protected]',
                firstName: 150,
                lastName: 'Doe 1',
                birthday: '04/07/1990',
                documentType: 'dni',
                documentNumber: '35319132',
                gender: 'male',
                phone: '22344569123',
                country: 'AR',
                address: 'Norway 120',
                enable: true
            };

            const response: IUserResponse = await request
                .put(`/api/users/${userId}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send(payload);

            const { body: { message, errors: [error] } } = response;

            expect(response.statusCode).toStrictEqual(422);
            expect(message).toStrictEqual('Failed Request.');

            expect(error.property).toStrictEqual('permissions');
            expect(error.constraints.isString).toBeDefined();
            expect(error.constraints.isString).toStrictEqual('each value in permissions must be a string');
        });

        test('Delete User error /users/:id', async() =>
        {
            const deleteErrorResponse: IUserResponse = await request
                .delete(`/api/users/${deleteResponse.body.data.id}`)
                .set('Accept', 'application/json')
                .set('Authorization', `Bearer ${token}`)
                .send();

            const { body: { message } } = deleteErrorResponse;

            expect(deleteErrorResponse.statusCode).toStrictEqual(400);
            expect(message).toStrictEqual('User not found.');
        });
    });
});