Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. function dataTest(filePath, expectedJSON, expectedJSONPath) {
  2. var app = request(targetUrl);
  3.  
  4. describe('Comparando ' + path.basename(filePath) + ' con ' + path.basename(expectedJSONPath), function() {
  5.  
  6. it('Debe coincidir con la respuesta esperada.', function(done) {
  7.  
  8.  
  9. this.timeout(60000);
  10.  
  11. var aux = app
  12. .post(targetConfig.PATH)
  13. .set('accept', 'application/json')
  14. .set('content-type', 'application/json')
  15. .set('host', targetConfig.HOST)
  16. .send({
  17. "requestId": "12",
  18. "invoiceFileName": path.basename(filePath).replace(//+/g, ''),
  19. "invoiceFileContents": fs.readFileSync(filePath).toString('base64')
  20. });
  21.  
  22. var aws_headers = signRequest(aux);
  23. aux.set('authorization', aws_headers.headers.Authorization).set('x-amz-date', aws_headers.headers['X-Amz-Date'])
  24. .expect(expectedJSON)
  25. .end(function(err, res) {
  26.  
  27. if (err) {
  28. if(expectedJSON === null) {
  29. try {
  30. fs.writeFileSync(expectedJSONPath, JSON.stringify(res.body, null, 2));
  31. console.log('nnAVISO -> GUARDADO NUEVO JSON SIN TESTEAR EN ' + expectedJSONPath + 'n');
  32. return done();
  33. }
  34. catch(err) {
  35. return done(err);
  36. }
  37. }
  38. else {
  39. console.error(err);
  40. return done(err);
  41. }
  42. }
  43. // Success
  44. done();
  45. });
  46. });
  47. });
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement