{"size": 1450, "ext": "js", "max_stars_repo_path": "test/unit/value-schema.test.js", "max_stars_repo_name": "uk-gov-mirror/defra.ffc-pr-calculator", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/unit/value-schema.test.js", "max_issues_repo_name": "uk-gov-mirror/defra.ffc-pr-calculator", "max_issues_repo_issues_event_min_datetime": "2021-02-19T17:06:07.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-13T13:50:40.000Z", "max_forks_repo_path": "test/unit/value-schema.test.js", "max_forks_repo_name": "uk-gov-mirror/defra.ffc-pr-calculator", "max_forks_repo_forks_event_min_datetime": "2021-04-10T21:32:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-10T21:32:34.000Z"}
{"max_stars_count": null, "max_issues_count": 54, "max_forks_count": 1, "avg_line_length": 33.7209302326, "max_line_length": 88, "alphanum_fraction": 0.6475862069}
const schema = require('../../app/routes/schemas/value')

describe('value schema validation', () => {
  test('is valid for integer', () => {
    const result = schema.validate({ value: 1000 })
    expect(result.error).toBeUndefined()
  })

  test('is valid for decimal', () => {
    const result = schema.validate({ value: 1000.12 })
    expect(result.error).toBeUndefined()
  })

  test('is valid for large number', () => {
    const result = schema.validate({ value: 10000000.99 })
    expect(result.error).toBeUndefined()
  })

  test('is invalid for 0', () => {
    const result = schema.validate({ value: 0 })
    expect(result.error).toBeDefined()
    expect(result.error.message).toBe('The value needs to be greater than £0.')
  })

  test('is invalid for negative number', () => {
    const result = schema.validate({ value: -1000 })
    expect(result.error).toBeDefined()
    expect(result.error.message).toBe('The value needs to be greater than £0.')
  })

  test('is invalid for not a number', () => {
    const result = schema.validate({ value: 'goats' })
    expect(result.error).toBeDefined()
    expect(result.error.message).toBe('The value must be a number without commas.')
  })

  test('is invalid for excessive number', () => {
    const result = schema.validate({ value: 1000000000000000000 })
    expect(result.error).toBeDefined()
    expect(result.error.message).toBe('The value needs to be less than £1,000,000,000.')
  })
})
