/**
 * @jest-environment node
*/
// @flow
import { fetchAuth, getRequest, postRequest } from './api'

const USERNAME: ?string = process.env.USERNAME
const PASSWORD: ?string = process.env.PASSWORD

describe('API', () => {
  if (!(USERNAME && PASSWORD)) {
    test.skip('skip api test')
    return
  }

  const info = {
    username: USERNAME,
    password: PASSWORD,
  }

  test('login success', async () => {
    const res = await fetchAuth(info)
    expect(res.user.account).toEqual(USERNAME)
  })

  test('no params', async () => {
    const { result } = await getRequest('/v1/illust/ranking?mode=day')
    expect(result).toHaveProperty('nextUrl')
  })

  test('have nextUrl', async () => {
    const { result } = await getRequest('/v1/illust/ranking', { mode: 'day' })
    expect(result).toHaveProperty('nextUrl')
  })

  test('get success', async () => {
    const { accessToken } = await fetchAuth(info)

    const { result } = await getRequest(
      '/v1/user/detail',
      { userId: 471355 },
      accessToken
    )
    expect(result).toHaveProperty('profile')
  })

  test('post success', async () => {
    const { accessToken } = await fetchAuth(info)

    const postData = await postRequest(
      '/v2/illust/bookmark/add',
      { illustId: 63576594, restrict: 'public' },
      accessToken
    )
    expect(postData).toEqual({})
  })
})

@@ -519,32 +519,82 @@
 , async () =%3E %7B%0A
+    const %7B accessToken %7D = await fetchAuth(info)%0A
     const %7B resu
@@ -609,32 +609,39 @@
 wait getRequest(
+%0A      
 '/v1/illust/rank
@@ -653,16 +653,50 @@
 ode=day'
+,%0A      %7B%7D,%0A      accessToken%0A    
 )%0A    ex
@@ -769,32 +769,82 @@
 , async () =%3E %7B%0A
+    const %7B accessToken %7D = await fetchAuth(info)%0A
     const %7B resu
@@ -867,16 +867,23 @@
 Request(
+%0A      
 '/v1/ill
@@ -895,16 +895,22 @@
 anking',
+%0A     
  %7B mode:
@@ -917,16 +917,40 @@
  'day' %7D
+,%0A      accessToken%0A    
 )%0A    ex

Fix test