{"size": 1534, "ext": "js", "max_stars_repo_path": "test/integration/configuration/show.js", "max_stars_repo_name": "luisolimpio/superbowleto", "max_stars_repo_stars_event_min_datetime": "2017-07-20T16:23:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T21:29:02.000Z", "max_issues_repo_path": "test/integration/configuration/show.js", "max_issues_repo_name": "luisolimpio/superbowleto", "max_issues_repo_issues_event_min_datetime": "2017-07-20T17:39:57.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T22:38:11.000Z", "max_forks_repo_path": "test/integration/configuration/show.js", "max_forks_repo_name": "luisolimpio/superbowleto", "max_forks_repo_forks_event_min_datetime": "2017-07-20T17:17:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T23:55:48.000Z"}
{"max_stars_count": 631, "max_issues_count": 77, "max_forks_count": 107, "avg_line_length": 23.6, "max_line_length": 71, "alphanum_fraction": 0.6544980443}
import cuid from 'cuid'
import test from 'ava'
import { assert } from '../../helpers/chai'
import { normalizeHandler } from '../../helpers/normalizer'
import { createConfig } from '../../helpers/configuration'
import configurationHandler from '../../../src/resources/configuration'
import database from '../../../src/database'

const { Configuration } = database.models
const showConfig = normalizeHandler(configurationHandler.show)
const externalId = cuid()

test.afterEach(async () => {
  await Configuration.destroy({
    where: {
      external_id: externalId,
    },
  })
})

test('shows an existing configuration', async (t) => {
  const configuration = await createConfig({
    external_id: externalId,
    issuer: 'bradesco',
  })

  const { body, statusCode } = await showConfig({
    params: {
      external_id: externalId,
    },
  })

  t.is(statusCode, 200)
  t.is(body.external_id, externalId)
  t.is(body.object, 'configuration')

  assert.containSubset(body, {
    external_id: externalId,
    issuer: 'bradesco',
    issuer_account: configuration.issuer_account,
    issuer_agency: configuration.issuer_agency,
    issuer_wallet: configuration.issuer_wallet,
  })
})

test('shows a non-existing configuration', async (t) => {
  const { body, statusCode } = await showConfig({
    params: {
      external_id: 'xxxxx',
    },
  })

  t.is(statusCode, 404)

  t.deepEqual(body, {
    errors: [
      {
        type: 'not_found',
        message: 'Configuration not found',
        field: null,
      },
    ],
  })
})
