/* eslint-env jest */

import UserModel from '../UserModel'
import setBackgroundImageFromCustomURL from '../setBackgroundImageFromCustomURL'
import {
  USER_BACKGROUND_OPTION_CUSTOM
} from '../../constants'
import {
  getMockUserContext,
  mockQueryMethods
} from '../../test-utils'

const user = getMockUserContext()
mockQueryMethods(UserModel)

describe('setBackgroundImageFromCustomURL', () => {
  it('works as expected', async () => {
    const imgUrl = 'https://imgur.com/fake-image/'
    await setBackgroundImageFromCustomURL(user, user.id, imgUrl)
    expect(UserModel.update).toHaveBeenCalledWith(user, {
      id: user.id,
      customImage: imgUrl,
      backgroundOption: USER_BACKGROUND_OPTION_CUSTOM
    })
  })
})

@@ -16,16 +16,44 @@
 est */%0A%0A
+import moment from 'moment'%0A
 import U
@@ -237,16 +237,37 @@
 mport %7B%0A
+  DatabaseOperation,%0A
   getMoc
@@ -286,51 +286,121 @@
 ,%0A  
-mockQueryMethods%0A%7D from '../../test-utils'%0A
+getMockUserInstance,%0A  mockDate,%0A  setMockDBResponse%0A%7D from '../../test-utils'%0A%0Ajest.mock('../../databaseClient')
 %0Acon
@@ -406,16 +406,23 @@
 nst user
+Context
  = getMo
@@ -441,34 +441,82 @@
 t()%0A
-mockQueryMethods(UserModel
+%0AbeforeAll(() =%3E %7B%0A  mockDate.on()%0A%7D)%0A%0AafterAll(() =%3E %7B%0A  mockDate.off()%0A%7D
 )%0A%0Ad
@@ -606,16 +606,72 @@
 () =%3E %7B%0A
+    const updateQuery = jest.spyOn(UserModel, 'update')%0A
     cons
@@ -763,14 +763,28 @@
 user
-, user
+Context, userContext
 .id,
@@ -807,24 +807,19 @@
 ect(
-UserModel.
 update
+Query
 ).to
@@ -841,16 +841,23 @@
 ith(user
+Context
 , %7B%0A    
@@ -866,16 +866,23 @@
 id: user
+Context
 .id,%0A   
@@ -962,14 +962,560 @@
 STOM
-%0A    %7D
+,%0A      updated: moment.utc().toISOString()%0A    %7D)%0A  %7D)%0A%0A  it('calls the database as expected', async () =%3E %7B%0A    const imgUrl = 'https://imgur.com/fake-image/'%0A    const expectedReturnedUser = getMockUserInstance()%0A    const dbUpdateMock = setMockDBResponse(%0A      DatabaseOperation.UPDATE,%0A      %7B%0A        Attributes: expectedReturnedUser%0A      %7D%0A    )%0A    const returnedUser = await setBackgroundImageFromCustomURL(userContext, userContext.id, imgUrl)%0A    expect(dbUpdateMock).toHaveBeenCalled()%0A    expect(returnedUser).toEqual(expectedReturnedUser
 )%0A  

Update tests.