1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| const practice = require('.');
test('case1 should get the first Huawei product in the list.', () => { const actual = practice.case1(); const expected = { "id": 5, "title": "Huawei P30", "description": "Huawei’s re-badged P30 Pro New Edition was officially unveiled yesterday in Germany and now the device has made its way to the UK.", "price": 499, "discountPercentage": 10.58, "rating": 4.09, "stock": 32, "brand": "Huawei", "category": "smartphones", "thumbnail": "https://dummyjson.com/image/i/products/5/thumbnail.jpg", "images": [ "https://dummyjson.com/image/i/products/5/1.jpg", "https://dummyjson.com/image/i/products/5/2.jpg", "https://dummyjson.com/image/i/products/5/3.jpg" ] };
expect(actual).toStrictEqual(expected); });
test('case2 should list all smartphones brands, without any duplicate.', () => { const actual = practice.case2(); const expected = [ 'Apple', 'Samsung', 'OPPO', 'Huawei', ];
expect(actual).toStrictEqual(expected); });
test('case3 should tell wether all fragrances products have stock over 100.', () => { const actual = practice.case3(); const expected = false;
expect(actual).toStrictEqual(expected); });
test('case4 should get the title of the lowest rating product in home-decoration category.', () => { const actual = practice.case4(); const expected = 'Plant Hanger For Home';
expect(actual).toStrictEqual(expected); });
test('case5 should tell whether there is any product lack of thumbnail.', () => { const actual = practice.case5(); const expected = false;
expect(actual).toStrictEqual(expected); });
test('case6 should tell wether all products have discountPercentage.', () => { const actual = practice.case6(); const expected = true;
expect(actual).toStrictEqual(expected); });
test('case7 should get the average rating for fragrances, round to 2 decimal places.', () => { const actual = practice.case7(); const expected = 4.35;
expect(actual).toStrictEqual(expected); });
test('case8 should list the discount price for all smartphones, round to 0 decimal places.', () => { const actual = practice.case8(); const expected = [ 71, 161, 193, 50, 53, ];
expect(actual).toStrictEqual(expected); });
test('case9 should determine that all products have one image at least.', () => { const actual = practice.case9(); const expected = true;
expect(actual).toStrictEqual(expected); });
test('case10 should determine that there is a product which description says "no side effects".', () => { const actual = practice.case10(); const expected = true;
expect(actual).toStrictEqual(expected); });
test('case11 should get the number of smartphones.', () => { const actual = practice.case11(); const expected = 5;
expect(actual).toStrictEqual(expected); });
test('case12 should get the brand of products which get over 4.9 rating.', () => { const actual = practice.case12(); const expected = [{ brand: 'fauji' }, { brand: 'Golden' }];
expect(actual).toStrictEqual(expected); });
test('case13 should get title of the first product of Dry Rose.', () => { const actual = practice.case13(); const expected = 'Gulab Powder 50 Gram';
expect(actual).toStrictEqual(expected); });
test('case14 should get the total revenue when all the products sold without discount.', () => { const actual = practice.case14(); const expected = 765200;
expect(actual).toStrictEqual(expected); });
test('case15 should get the top 3 highest discounted product brands.', () => { const actual = practice.case15(); const expected = ['Apple', 'OPPO', 'Boho Decor'];
expect(actual).toStrictEqual(expected); });
test('case16 should get the number of product brands.', () => { const actual = practice.case16(); const expected = 28;
expect(actual).toStrictEqual(expected); });
|