import { test } from '@japa/runner'
import { ApiExampleGenerator } from '../../../src/amf/ApiExampleGenerator.js'
import { IAmfDocument } from '../../../src/amf/definitions/Amf.js'
import { IApiAnyShape } from '../../../src/amf/definitions/Shapes.js'
import { AmfLoader } from './AmfLoader.js'

test.group('APIC-233', (group) => {
  const loader = new AmfLoader()
  const jsonMime = 'application/json'
  const apiFile = 'APIC-233'

  let reader: ApiExampleGenerator
  let model: IAmfDocument

  group.setup(async () => {
    model = await loader.getGraph(apiFile)
    reader = new ApiExampleGenerator()
  })

  test('renders examples for arabic letters', ({ assert }) => {
    const payload = loader.getResponsePayloads(model, '/stuff', 'get', '200')[0]
    const anyShape = payload.schema as IApiAnyShape

    const result = reader.read(anyShape.examples[0], jsonMime) as string
    const body = JSON.parse(result)
    assert.typeOf(body, 'object', 'has the result')
    assert.deepEqual(body, {
      الحالة: 'حسنا',
      message: 'Shop in الممل',
    })
  })
})
