express#response JavaScript Examples

The following examples show how to use express#response. 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: passage.test.js    From 2020.1-Ziguen with GNU General Public License v3.0 6 votes vote down vote up
describe('Create', () => {
    it('returns status 400 to failure', async() => {

        const user = await factory.attrs('Admin');
        await request(app).post('/admins').send(user);

        const trip = await factory.attrs('Trip',{
            user_id: 1
        });
        await request(app).post('/trips').send(trip);

        const traveler = await factory.attrs('Traveler');
        await request(app).post('/travelers').send(traveler);

        const passage = await factory.attrs('Passage',{

            traveler_id: 1,
            trip_id: 1
        });
        const response = await request(app).post('/passages').send(passage);
    
        expect(response.status).toBe(400);
    })

    it('should return status 400, if data is null', async() => {
        
       
        const passage = await factory.attrs('Passage',{
          
            traveler_id: null,
            trip_id: null
        });
        const response = await request(app).post('/passages').send(passage);
    
        expect(response.status).toBe(400);
    })
})
Example #2
Source File: passage.test.js    From 2020.1-Ziguen with GNU General Public License v3.0 6 votes vote down vote up
describe('Update', () => {
    it('Should return status 401, if Authorization error', async() =>{
        const tok = 1234;

        const passage = await factory.attrs('Passage',{
           
            traveler_id: 1,
            trip_id: 1,
        });
        await request(app).post('/passages').send(passage);

        await request(app).put('/admins').set('authorization',tok)

        const response = await request(app).put('/passages').send(passage);
        
        expect(response.status).toBe(401);
    })
})
Example #3
Source File: passage.test.js    From 2020.1-Ziguen with GNU General Public License v3.0 6 votes vote down vote up
describe('Index', () =>  {
    it('Should return status 200, if listing is successful', async() => {
        await factory.createMany('Passage',1)
        const response = await request(app).get('/passages').set('authorization', `Bearer ${await adminSession()}`)

        expect(response.status).toBe(200);
    })

    it('Should return status 401, if listing is not successful', async() => {
        const tok = 123456
        await factory.createMany('Passage',1)
        const response = await request(app).get('/passages').set('authorization', tok)

        expect(response.status).toBe(401);
    })
})
Example #4
Source File: passage.test.js    From 2020.1-Ziguen with GNU General Public License v3.0 6 votes vote down vote up
describe ('Descript', () => { 
    it('Should return status 200, if descript is sucessful', async() => {
        await factory.create('Passage')
        const response = await request(app).get('/passages/1').set('authorization', `Bearer ${await adminSession()}`)
        

        expect(response.status).toBe(200);
 
    })

    it('Should return status 401, if descript is not sucessful', async() => {
        const tok = 12390
        await factory.create('Passage')
        const response = await request(app).get('/passages').set('authorization', tok)
        

        expect(response.status).toBe(401);
    })
})
Example #5
Source File: passage.test.js    From 2020.1-Ziguen with GNU General Public License v3.0 5 votes vote down vote up
describe('Delete', () => {
    it('Should return status 500, if deleting is not successful', async() => {
        await factory.create('Passage')
        const response = await request(app).delete('/passages').set('authorization', `Bearer ${await adminSession()}`)

        expect(response.status).toBe(500);
    })
})