import resolveModel from "../resolveModel";
import ModularUIResponse from "../../modularui/ModularUIResponse";
import ApplicationModel from "../application/ApplicationModel";
import { IllegalArgumentException } from "../../exceptions";

describe("resolveModel", () => {
  it("should be able to resolve a model based on modular ui contributions", () => {
    expect(() => {
      resolveModel();
    }).toThrow(IllegalArgumentException);

    expect(() => {
      resolveModel({});
    }).toThrow(IllegalArgumentException);

    const NonExistingModularUIResponse = ModularUIResponse.create({
      key: "non",
      data: { non: {} },
      contributions: { non: { resourcetype: "nonexisting" } },
    });

    const NonExisting = resolveModel(NonExistingModularUIResponse);
    expect(NonExisting).toBeNull();

    const ApplicationModularUIResponse = ModularUIResponse.create({
      key: "app",
      data: { app: {} },
      contributions: { app: { resourcetype: "Application" } },
    });

    const App = resolveModel(ApplicationModularUIResponse);
    expect(App === ApplicationModel).toBeTruthy();
  });
});
