'use strict';

// ------- Imports -------------------------------------------------------------

const chai = require('chai');
const fetch = require('node-fetch');
const test = require('ava');

const BlinkWorkerApp = require('../../src/app/BlinkWorkerApp');
const MessageFactoryHelper = require('../helpers/MessageFactoryHelper');

// ------- Init ----------------------------------------------------------------

chai.should();
const { Response } = fetch;

// ------- Tests ---------------------------------------------------------------

test('Gambit should recieve correct retry count if message has been retried', () => {
  const config = require('../../config');
  const gambitWorkerApp = new BlinkWorkerApp(config, 'gambit-message-data-relay');
  const gambitWorker = gambitWorkerApp.worker;

  // No retry property:
  gambitWorker.getRequestHeaders(MessageFactoryHelper.getValidMessageData())
    .should.not.have.property('x-blink-retry-count');

  // retry = 0
  const retriedZero = MessageFactoryHelper.getValidMessageData();
  retriedZero.payload.meta.retry = 0;
  gambitWorker.getRequestHeaders(retriedZero)
    .should.not.have.property('x-blink-retry-count');

  // retry = 1
  const retriedOnce = MessageFactoryHelper.getValidMessageData();
  retriedOnce.payload.meta.retry = 1;
  gambitWorker.getRequestHeaders(retriedOnce)
    .should.have.property('x-blink-retry-count').and.equal(1);
});


// test('Test Gambit response with x-blink-retry-suppress header', () => {
//   const config = require('../../config');
//   const gambitWorkerApp = new BlinkWorkerApp(config, 'gambit-chatbot-mdata-proxy');
//   const gambitWorker = gambitWorkerApp.worker;

//   // Gambit order retry suppression
//   const retrySuppressResponse = new Response(
//     'Unknown Gambit error',
//     {
//       status: 422,
//       statusText: 'Unknown Gambit error',
//       headers: {
//         // Also make sure that blink recongnizes non standart header case
//         'X-BlInK-RetRY-SuPPRESS': 'TRUE',
//       },
//     },
//   );

//   gambitWorker.checkRetrySuppress(retrySuppressResponse).should.be.true;


//   // Normal Gambit 422 response
//   const normalFailedResponse = new Response(
//     'Unknown Gambit error',
//     {
//       status: 422,
//       statusText: 'Unknown Gambit error',
//       headers: {
//         'x-taco-count': 'infinity',
//       },
//     },
//   );
//   gambitWorker.checkRetrySuppress(normalFailedResponse).should.be.false;
// });

// ------- End -----------------------------------------------------------------

@@ -1402,19 +1402,16 @@
 ;%0A%7D);%0A%0A%0A
-// 
 test('Te
@@ -1474,19 +1474,16 @@
 () =%3E %7B%0A
-// 
   const 
@@ -1512,27 +1512,24 @@
 ./config');%0A
-// 
   const gamb
@@ -1581,34 +1581,30 @@
 bit-
-chatbot-m
+message-
 data-
-prox
+rela
 y');%0A
-// 
   co
@@ -1647,19 +1647,16 @@
 orker;%0A%0A
-// 
   // Gam
@@ -1683,19 +1683,16 @@
 ression%0A
-// 
   const 
@@ -1721,35 +1721,32 @@
 = new Response(%0A
-// 
     'Unknown Gam
@@ -1753,36 +1753,30 @@
 bit error',%0A
-//
     
- 
 %7B%0A
-// 
       status
@@ -1774,35 +1774,32 @@
    status: 422,%0A
-// 
       statusText
@@ -1816,35 +1816,32 @@
  Gambit error',%0A
-// 
       headers: %7B
@@ -1833,35 +1833,32 @@
      headers: %7B%0A
-// 
         // Also 
@@ -1915,19 +1915,16 @@
 er case%0A
-// 
         
@@ -1957,19 +1957,16 @@
 'TRUE',%0A
-// 
       %7D,
@@ -1970,32 +1970,23 @@
  %7D,%0A
-// 
     %7D,%0A
-// 
   );%0A%0A
-//
   
- 
 gamb
@@ -2054,19 +2054,16 @@
 true;%0A%0A%0A
-// 
   // Nor
@@ -2086,19 +2086,16 @@
 esponse%0A
-// 
   const 
@@ -2131,19 +2131,16 @@
 sponse(%0A
-// 
     'Unk
@@ -2163,20 +2163,14 @@
 r',%0A
-// 
     %7B%0A
-// 
     
@@ -2184,19 +2184,16 @@
 s: 422,%0A
-// 
       st
@@ -2226,19 +2226,16 @@
 error',%0A
-// 
       he
@@ -2243,19 +2243,16 @@
 ders: %7B%0A
-// 
         
@@ -2283,41 +2283,29 @@
 y',%0A
-//
       
- 
 %7D,%0A
-//
     
- 
 %7D,%0A
-// 
   );%0A
-// 
   ga
@@ -2373,19 +2373,16 @@
 .false;%0A
-// 
 %7D);%0A%0A// 

Add test for x-blink-retry-suppress