摩卡咖啡:套件中所有测试总结后的测试通过

时间:2018-10-22 08:13:49

标签: javascript mocha

这是地雷测试班之一

const fs = require('fs');
const chai = require('chai');
const config = require('../config');
const request = require('supertest')(config.url);
const assert = chai.assert;
require('mocha');



var log4js = require('log4js');
var logger = log4js.getLogger('08_order'); 
log4js.configure({
  appenders: {
    out:{ type: 'console' },
    app:{ type: 'file', filename: 'logs/log.log' }
  },
  categories: {
    default: { appenders: [ 'out', 'app' ], level: 'info' }
  }
})




var dineInOrderDetails=[];
var deliveryOrderDetails=[];




describe('order', function() {
  this.timeout(10000);



   it('should submit simple product order for dine in', function(done) {
    request
      .post('/rest/v2/order/submit')
      .set(config.headers)
      .set('Authorization', 'Bearer ' + auth_token) 
      //.set('Accept', 'application/json')  
      .send(
        {  
          "restaurantId":dineInRestaurantId,
          "deliveryAddress":{  
             "city":dineInRestaurantCity,
             "street":dineInRestaurantStreet,
             "houseNumber":dineInRestaurantStreetNo,
             "lat":dineInRestaurantGeoLat,
             "lng":dineInRestaurantGeoLng,
             "inDeliveryZone":true
       
          },
          "deliveryType":"DINE_IN",
          "deliveryTime":"14:24",
          "paymentType":"CARD_DEL",
          "customer":{  
             "phoneNumber":"530323370",
             "firstName":"Imie",
             "emailAddress":"x@x.pl",
             "customerName":"Imie"
          },
          "agreements":{  
             "acceptTerms":true,
             "acceptDataProcessingAgreement":true
          },
          "basket":{  
             "basketLines":[  
                {  
                   "uuid":"uuid",
                   "quantity":2,
                   "product":{  
                      "id": randomAvailableSimpleProductIdForDineIn
                   }
                }
             ]
          }
       } 
      )
      .end(function(err,res){
        logger.info(config.logToConsole(res.request.url,res.request._data));
        assert.equal(res.status,200);
        assert.containsAllKeys(res.body,['uuid','totalGross','totalAmount','orderNo','orderStatus','deliveryTime']);
        logger.info('uuid: ',res.body.uuid);
        dineInOrderDetails[0]=res.body.uuid;
        dineInOrderDetails[1]=res.body.totalGross;
        dineInOrderDetails[2]=res.body.totalAmount;
        done(err);
      });    
   });



   it('should return details of last order', function(done) {
    tempUrl="/rest/v1/user/orders/"+dineInOrderDetails[0];
    request 
      .get(tempUrl)
      .set(config.headers)
      .set('Authorization', 'Bearer ' + auth_token)
      .end(function(err,res){
        logger.info(config.logToConsole(res.request.url,res.request._data));
        assert.equal(res.status,200);
        assert.equal(res.body.order.uuid, dineInOrderDetails[0]);
        assert.equal(res.body.order.totalGross, dineInOrderDetails[1]);
        assert.equal(res.body.order.totalAmount, dineInOrderDetails[2]);
        done(err);
      });        
   });



   it('should return recent orders', function(done) {
    request 
      .get("/rest/v1/user/orders")
      .set(config.headers)
      .set('Authorization', 'Bearer ' + auth_token)
      .end(function(err,res){
        logger.info(config.logToConsole(res.request.url));
        assert.equal(res.status,200);
        assert.isArray(res.body.orders);
        assert.containsAllKeys(res.body.orders[0],'uuid','totalGross','totalAmount','cellPhone','deliveryTime','currency','addedAtDate',
          'isClaim','isFavourite','status','orderNumber','restaurant','zipCode');
        done(err);
      });        
   });

//done(err);
});

测试在docker本地运行,我也使用mailhog接收短信和邮件。 在大多数情况下,如果我运行测试,则第一个测试:“应提交进餐的简单产品订单”正在等待10秒超时,然后失败,在控制台中,我收到失败摘要:

  

2)订单          请在以下位置提交简单的产品订购订单:        错误:超时超过10000ms。对于异步测试和挂钩,请确保调用了“ done()”;如果返回承诺,请确保其解决。   (C:\ dockerApi \ test \ 08_order.js)

并且在控制台中的失败摘要之后,我收到此情况已通过正确发送的正文传递的信息。为什么我在完成所有测试后会收到通过信息?

您有这样的问题吗?

0 个答案:

没有答案