Guruh talabasi Norqobilov Akmal Unit test const


const category = new Category({ name: 'sun\'iy idrok' }); await category.save(); const



Download 417,53 Kb.
bet5/5
Sana03.01.2022
Hajmi417,53 Kb.
#228131
1   2   3   4   5
Bog'liq
testlash

const category = new Category({ name: 'sun\'iy idrok' });

await category.save();
const response = await request(server).get('/api/categories/' + category._id);

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

expect(response.body).toHaveProperty('name', 'sun\'iy idrok');

});
it('should return 404 if invalid id is given', async () => {

const response = await request(server).get('/api/categories/123');

expect(response.status).toBe(404);

});
it('should return 404 if no category with the passed id exist', async () => {

const categoryId = mongoose.Types.ObjectId();

const response = await request(server).get('/api/categories/' + categoryId);

expect(response.status).toBe(404);

});

});
describe('POST /', () => {

let token;

let name;
// testlar uchun ishlatiladigan funktsiyani bu yerda oldindan

// aniqlab olamiz va uni har bir test ichida alohida chaqiramiz

const execute = async () => {

return await request(server)

.post('/api/categories')

.set('x-auth-token', token)

.send({ name });

}
beforeEach(() => {

token = new User().generateAuthToken();

name = 'dasturlash';

})
it('should return 401 if user is not logged in', async () => {

token = '';

const res = await execute();

expect(res.status).toBe(401);

});
it('should return 400 if category name is less than 3 characters', async () => {

name = '12';

const res = await execute();

expect(res.status).toBe(400);

});
it('should return 400 if category name is more than 50 characters', async () => {

name = new Array(52).join('c');

const res = await execute();

expect(res.status).toBe(400);

});
it('should save the category if it is valid', async () => {

await execute();

const category = await Category.find({ name: 'dasturlash' });

expect(category).not.toBeNull();

});
it('should return the category if it is valid', async () => {

const res = await execute();

expect(res.body).toHaveProperty('_id');

expect(res.body).toHaveProperty('name', 'dasturlash');

});

});

});

Test natijasi


Download 417,53 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish