const ArticleQueue = require('../../structs/ArticleQueue.js')
const configuration = require('../../config.js')

jest.mock('../../config.js')

const bot = {
  shard: {
    ids: [1]
  }
}

jest.useFakeTimers()

describe('Unit::structs/ArticleQueue', function () {
  beforeEach(async () => {
    configuration.get.mockReturnValue({
      feeds: {
        articleDequeueRate: 0.01
      }
    })
  })
  afterEach(() => {
    jest.resetAllMocks()
  })
  describe('enqueue', () => {
    it('adds the data to the queue', () => {
      const newArticle = {
        foo: 'baz'
      }
      const articleMessage = {
        foh: 'ban'
      }
      const queue = new ArticleQueue({ ...bot })
      queue.enqueue(newArticle, articleMessage)
      expect(queue.queue).toEqual([{
        newArticle,
        articleMessage
      }])
    })
  })
  describe('dequeue', () => {
    beforeEach(() => {
      jest.spyOn(ArticleQueue.prototype, 'recordSuccess')
        .mockImplementation()
      jest.spyOn(ArticleQueue.prototype, 'recordFailure')
        .mockImplementation()
    })
    it('sends the right article messages', async () => {
      const message1Send = jest.fn()
      const message2Send = jest.fn()
      const message3Send = jest.fn()
      const articleDataQueue = [{
        articleMessage: {
          id: 1, // for debugging
          send: message1Send
        }
      }, {
        articleMessage: {
          id: 2,
          send: message2Send
        }
      }, {
        articleMessage: {
          id: 3,
          send: message3Send
        }
      }]
      const queue = new ArticleQueue({ ...bot })
      queue.queue = articleDataQueue
      await queue.dequeue(2)
      expect(message1Send)
        .toHaveBeenCalledTimes(1)
      expect(message2Send)
        .toHaveBeenCalledTimes(1)
      expect(message3Send)
        .toHaveBeenCalledTimes(0)
    })
  })
  describe('constructor', () => {
    it.only('creates the interval correctly for rate of <1', () => {
      configuration.get.mockReturnValue({
        feeds: {
          articleDequeueRate: 0.2
        }
      })
      // eslint-disable-next-line no-new
      const queue = new ArticleQueue({ ...bot })
      queue.dequeue = jest.fn()
      const expectedDequeueRate = 1
      const expectedInterval = 5000
      expect(setInterval)
        .toHaveBeenCalledWith(expect.any(Function), expectedInterval)
      expect(setInterval).toHaveBeenCalledTimes(1)
      jest.advanceTimersByTime(expectedInterval)
      expect(queue.dequeue).toHaveBeenCalledWith(expectedDequeueRate)
    })
    it('creates interval correctly for rate of >1', () => {
      configuration.get.mockReturnValue({
        feeds: {
          articleDequeueRate: 5
        }
      })
      const queue = new ArticleQueue({ ...bot })
      queue.dequeue = jest.fn()
      const expectedDequeueRate = 5
      const expectedInterval = 1000
      expect(setInterval)
        .toHaveBeenCalledWith(expect.any(Function), expectedInterval)
      expect(setInterval).toHaveBeenCalledTimes(1)
      jest.advanceTimersByTime(expectedInterval)
      expect(queue.dequeue).toHaveBeenCalledWith(expectedDequeueRate)
    })
  })
})

@@ -184,30 +184,8 @@
 %0A%7D%0A%0A
-jest.useFakeTimers()%0A%0A
 desc
@@ -369,52 +369,107 @@
 )%0A  
-%7D)%0A  afterEach(() =%3E %7B%0A    jest.resetAllMock
+  jest.spyOn(ArticleQueue.prototype, '_logDebug')%0A      .mockImplementation()%0A    jest.useFakeTimer
 s()%0A
@@ -958,109 +958,12 @@
 e, '
-recordSuccess')%0A        .mockImplementation()%0A      jest.spyOn(ArticleQueue.prototype, 'recordFailure
+send
 ')%0A 
@@ -1059,119 +1059,8 @@
 %3E %7B%0A
-      const message1Send = jest.fn()%0A      const message2Send = jest.fn()%0A      const message3Send = jest.fn()%0A
     
@@ -1082,47 +1082,14 @@
 Data
-Queue
+1
  = 
-%5B
 %7B%0A
-        articleMessage: %7B%0A  
     
@@ -1097,17 +1097,16 @@
    id: 1
-,
  // for 
@@ -1125,30 +1125,38 @@
     
+%7D%0A
     
-send: message1Send
+  const articleData2 = %7B
 %0A   
@@ -1156,33 +1156,37 @@
 = %7B%0A        
-%7D
+id: 2
 %0A      %7D
 , %7B%0A        
@@ -1173,35 +1173,36 @@
 %0A      %7D
-, %7B
 %0A      
- 
+const
  article
 Message:
@@ -1189,37 +1189,34 @@
 onst article
-Message:
+Data3 =
  %7B%0A
-  
         id: 
@@ -1219,150 +1219,122 @@
 id: 
-2,
+3
 %0A     
+ %7D%0A
      
-send: message2Send%0A        %7D%0A      %7D, %7B%0A
+ const articleDataQueue = %5B%0A   
      
-   
 article
-Message: %7B%0A          id: 3,%0A          send: message3Send%0A        %7D%0A      %7D
+Data1,%0A        articleData2,%0A        articleData3%0A      
 %5D%0A  
@@ -1417,16 +1417,45 @@
 taQueue%0A
+      queue.send = jest.fn()%0A
       aw
@@ -1472,16 +1472,29 @@
 dequeue(
+queue.queue, 
 2)%0A     
@@ -1505,17 +1505,15 @@
 ect(
-message1S
+queue.s
 end)
@@ -1536,33 +1536,33 @@
 BeenCalledTimes(
-1
+2
 )%0A      expect(m
@@ -1564,17 +1564,15 @@
 ect(
-message2S
+queue.s
 end)
@@ -1589,38 +1589,48 @@
 toHaveBeenCalled
-Times(
+With(articleData
 1)%0A      expect(
@@ -1633,17 +1633,15 @@
 ect(
-message3S
+queue.s
 end)
@@ -1670,15 +1670,98 @@
 lled
-Times(0
+With(articleData2)%0A      expect(queue.send)%0A        .not.toHaveBeenCalledWith(articleData3
 )%0A  
@@ -1814,13 +1814,8 @@
   it
-.only
 ('cr
@@ -2094,32 +2094,99 @@
 eue = jest.fn()%0A
+      queue.queue = %5B1, 3, 4%5D%0A      queue.serviceBacklogQueue = %5B%5D%0A
       const expe
@@ -2478,32 +2478,45 @@
 eBeenCalledWith(
+queue.queue, 
 expectedDequeueR
@@ -2738,32 +2738,62 @@
 eue(%7B ...bot %7D)%0A
+      queue.queue = %5B4, 5, 6%5D%0A
       queue.dequ
@@ -3121,24 +3121,37 @@
 nCalledWith(
+queue.queue, 
 expectedDequ

Fix tests