import { fixture, assert, html } from '@open-wc/testing';
import { AmfDefinitions, ApiDefinitions } from '@api-client/core/build/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('oauth-pkce');
  });

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

  describe('PKCE extension', () => {
    let element: AmfOauth2;

    beforeEach(async () => {
      const scheme = getApiParametrizedSecurityScheme('/pkce', 'get');
      element = await methodFixture(scheme);
    });

    it('sets the `pkce` property to true', () => {
      assert.isTrue(element.config.pkce);
    });
  });
});
