<commit_before>import chai from 'chai';
import request from 'supertest';
import app from '../../src/app';
import { ADMINISTRATOR } from '../../src/auth/constants';
import { loadFixtures, test404, createAuthorization } from '../helpers';

chai.should();

const headers = {
    Authorization: createAuthorization(ADMINISTRATOR)
};

describe('APIToken API', () => {
    describe('List all tokens', () => {
        beforeEach(() => loadFixtures());

        it('should list all tokens', done => {
            request(app)
            .get('/api-tokens/')
            .set(headers)
            .expect('Content-Type', /json/)
            .expect(200)
            .end((err, res) => {
                if (err) return done(err);
                const tokens = res.body;
                const [token] = tokens;
                tokens.length.should.equal(2);
                token.id.should.equal(1);
                token.name.should.equal('test token');
                done();
            });
        });
    });

    describe('Create token', () => {
        it('should generate a new token', done => {
            const body = {
                name: 'test',
                systemId: 1
            };

            request(app)
            .post('/api-tokens')
            .send(body)
            .set(headers)
            .expect('Content-Type', /json/)
            .expect(201)
            .end((err, res) => {
                if (err) return done(err);
                const auth = res.body;
                auth.token.length.should.equal(32);
                auth.name.should.equal(body.name);
                done();
            });
        });

        it('should return a validation error for missing info', done => {
            const auth = {
                systemId: 1
            };

            request(app)
            .post('/api-tokens/')
            .send(auth)
            .set(headers)
            .expect('Content-Type', /json/)
            .expect(400)
            .end((err, res) => {
                if (err) return done(err);
                res.body.message.should.equal('notNull Violation: name cannot be null');
                res.body.errors.length.should.equal(1);
                done();
            });
        });
    });

    describe('Delete token', () => {
        beforeEach(() => loadFixtures());

        it('should delete a token', done => {
            request(app)
            .delete('/api-tokens/1')
            .set(headers)
            .expect(204)
            .end((err, res) => {
                if (err) return done(err);
                done();
            });
        });

        it('should return 404 for missing tokens', done => {
            test404('/api-tokens/1337', done, headers, 'delete');
        });
    });
});<commit_msg>Fix api token tests by adding system id to urls<commit_after>import chai from 'chai';
import request from 'supertest';
import app from '../../src/app';
import { ADMINISTRATOR } from '../../src/auth/constants';
import { loadFixtures, test404, createAuthorization } from '../helpers';

chai.should();

const headers = {
    Authorization: createAuthorization(ADMINISTRATOR)
};

describe('APIToken API', () => {
    describe('List all tokens', () => {
        beforeEach(() => loadFixtures());

        it('should list all tokens', done => {
            request(app)
            .get('/1/api-tokens/')
            .set(headers)
            .expect('Content-Type', /json/)
            .expect(200)
            .end((err, res) => {
                if (err) return done(err);
                const tokens = res.body;
                const [token] = tokens;
                tokens.length.should.equal(2);
                token.id.should.equal(1);
                token.name.should.equal('test token');
                done();
            });
        });
    });

    describe('Create token', () => {
        it('should generate a new token', done => {
            const body = {
                name: 'test',
                systemId: 1
            };

            request(app)
            .post('/1/api-tokens/')
            .send(body)
            .set(headers)
            .expect('Content-Type', /json/)
            .expect(201)
            .end((err, res) => {
                if (err) return done(err);
                const auth = res.body;
                auth.token.length.should.equal(32);
                auth.name.should.equal(body.name);
                done();
            });
        });

        it('should return a validation error for missing info', done => {
            const auth = {
                systemId: 1
            };

            request(app)
            .post('/1/api-tokens/')
            .send(auth)
            .set(headers)
            .expect('Content-Type', /json/)
            .expect(400)
            .end((err, res) => {
                if (err) return done(err);
                res.body.message.should.equal('notNull Violation: name cannot be null');
                res.body.errors.length.should.equal(1);
                done();
            });
        });
    });

    describe('Delete token', () => {
        beforeEach(() => loadFixtures());

        it('should delete a token', done => {
            request(app)
            .delete('/1/api-tokens/1/')
            .set(headers)
            .expect(204)
            .end((err, res) => {
                if (err) return done(err);
                done();
            });
        });

        it('should return 404 for missing tokens', done => {
            test404('/1/api-tokens/1337', done, headers, 'delete');
        });
    });
});
{'fraction_non_alphanumeric': 0.15460057061340943, 'fraction_numerical': 0.012660485021398002, 'mean_word_length': 1.3400083437630372, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7456992', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1482, 'n_words': 331}