import { fixture, assert, html } from '@open-wc/testing'
import { AmfDefinitions, ApiDefinitions, IOAuth2Authorization } from '@api-client/core/browser.js'
import { AmfLoader } from '../AmfLoader.js'
import AmfOauth2 from '../../../src/elements/amf/authorization/AmfOauth2.js'
import '../../../src/define/amf/authorization/amf-oauth2-authorization.js'

describe.skip('OAuth 2', () => {
  async function methodFixture(security?: ApiDefinitions.IApiParametrizedSecurityScheme): Promise<AmfOauth2> {
    return fixture(html`<amf-oauth2-authorization .security="${security}"></amf-oauth2-authorization>`)
  }

  let store: AmfLoader
  let model: AmfDefinitions.IAmfDocument
  before(async () => {
    store = new AmfLoader()
    model = await store.getGraph('21143')
  })

  function getApiParametrizedSecurityScheme(
    path: string,
    method: string
  ): ApiDefinitions.IApiParametrizedSecurityScheme {
    const operation = store.getOperation(model, path, method)
    return operation.security[0].schemes[0]
  }

  describe('Application flow', () => {
    let element: AmfOauth2

    beforeEach(async () => {
      const scheme = getApiParametrizedSecurityScheme('/myz-api/claims/claims', 'get')
      element = await methodFixture(scheme)
    })

    it('should set grant type to client_credentials', () => {
      const details = element.serialize() as IOAuth2Authorization
      assert.equal(details.grantType, 'client_credentials')
    })
  })
})
