<commit_before>import request from 'supertest';
import app from '../../src/app';

describe('Test the /user/:username route', () => {
    it('should get a user given a username', (done) => {
        request(app)
            .get('/api/user/test')
            .expect(404)
            .end(() => {
                done();
            });
    });
});
<commit_msg>Updated user route test suite<commit_after>import request from 'supertest';
import chai from 'chai';

import app from '../../src/app';
import acquireJwt from '../common/jwt.common';
import { setupUserCollection, destroyUsersCollection } from '../mocks/user.mock';

const { expect } = chai;

describe('Test the /user route', () => {
    let jwt = '';
    beforeEach((done) => {
        setupUserCollection().then(() => {
            done();
        }).catch((err) => {
            done(err);
        });
    });
    beforeEach((done) => {
        acquireJwt(app).then((res) => {
            jwt = res.body.token;
            done();
        }).catch((err) => {
            done(err);
        });
    });
    afterEach((done) => {
        destroyUsersCollection().then(() => {
            done();
        }).catch((err) => {
            done(err);
        });
    });
    describe('/:username', () => {
        describe('GET', () => {
            it('should retrieve a single user', (done) => {
                request(app)
                    .get('/api/user/testuser')
                    .expect(200)
                    .end((err, res) => {
                        if (err) {
                            return done(err);
                        }
                        expect(res.body.data.username).to.be.eq('testuser');
                        expect(res.body.data.name).to.be.eq('Test User');
                        expect(res.body.data.email).to.be.eq('<EMAIL>');
                        return done();
                    });
            });
            it('should fail to retrieve a single user', (done) => {
                request(app)
                    .get('/api/user/nouser')
                    .expect(404, done);
            });
        });
        describe('PUT', () => {
            it('should update a single user', (done) => {
                request(app)
                    .put('/api/user/testuser')
                    .set({ Authorization: `Bearer ${jwt}` })
                    .send({
                        name: '<NAME>'
                    })
                    .expect(200)
                    .end((err, res) => {
                        if (err) {
                            return done(err);
                        }
                        expect(res.body.data.name).to.be.eq('<NAME>');
                        return done();
                    });
            });
            it('should not update the user since the user could not be found', (done) => {
                request(app)
                    .put('/api/user/nouser')
                    .set({ Authorization: `Bearer ${jwt}` })
                    .send({
                        name: '<NAME>'
                    })
                    .expect(404, done);
            });
        });
        describe('DELETE', () => {
            it('should delete a single user', (done) => {
                request(app)
                    .delete('/api/user/testuser')
                    .set({ Authorization: `Bearer ${jwt}` })
                    .expect(200)
                    .end((err, res) => {
                        if (err) {
                            return done(err);
                        }
                        expect(res.body.data).to.be.eq('The user with the username testuser was removed');
                        return done();
                    });
            });
            it('should not delete the user since the user could not be found', (done) => {
                request(app)
                    .delete('/api/user/nouser')
                    .set({ Authorization: `Bearer ${jwt}` })
                    .expect(404, done);
            });
        });
    });
});

{'fraction_non_alphanumeric': 0.1577263779527559, 'fraction_numerical': 0.00516732283464567, 'mean_word_length': 1.0571862348178138, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4603350', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1008, 'n_words': 212}