"use client";
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }

var _chunk3EPNHTMHjs = require('../chunk-3EPNHTMH.js');


var _chunk7QVYU63Ejs = require('../chunk-7QVYU63E.js');

// src/testing/providers/MockJsonApiProvider.tsx
var _jsxruntime = require('react/jsx-runtime');
var defaultMockConfig = {
  apiUrl: "https://api.test.com",
  tokenGetter: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, async () => "mock-token-for-testing", "tokenGetter"),
  languageGetter: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, async () => "en", "languageGetter"),
  defaultHeaders: {},
  onError: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => {
  }, "onError"),
  cacheConfig: {
    defaultProfile: "default"
  }
};
function MockJsonApiProvider({ children, config }) {
  const mergedConfig = {
    ...defaultMockConfig,
    ...config
  };
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk3EPNHTMHjs.JsonApiContext.Provider, { value: mergedConfig, children });
}
_chunk7QVYU63Ejs.__name.call(void 0, MockJsonApiProvider, "MockJsonApiProvider");

// src/testing/factories/createMockModule.ts
function createMockModule(options) {
  class MockModel {constructor() { MockModel.prototype.__init.call(this);MockModel.prototype.__init2.call(this); }
    static {
      _chunk7QVYU63Ejs.__name.call(void 0, this, "MockModel");
    }
    __init() {this.id = "mock-id"}
    __init2() {this.type = options.name}
  }
  return {
    name: options.name,
    cache: options.cache,
    inclusions: options.inclusions,
    model: MockModel
  };
}
_chunk7QVYU63Ejs.__name.call(void 0, createMockModule, "createMockModule");

// src/testing/factories/createMockResponse.ts
function createMockResponse(options = {}) {
  const {
    data = null,
    ok = true,
    response = ok ? 200 : 500,
    error = ok ? "" : "Error",
    meta,
    self,
    next,
    prev
  } = options;
  const mockResponse = {
    ok,
    response,
    data,
    error,
    meta,
    self,
    next,
    prev
  };
  if (next) {
    mockResponse.nextPage = async () => createMockResponse({ ...options, next: void 0, prev: self });
  }
  if (prev) {
    mockResponse.prevPage = async () => createMockResponse({ ...options, prev: void 0, next: self });
  }
  return mockResponse;
}
_chunk7QVYU63Ejs.__name.call(void 0, createMockResponse, "createMockResponse");
function createMockErrorResponse(statusCode, errorMessage) {
  return createMockResponse({
    ok: false,
    response: statusCode,
    error: errorMessage,
    data: null
  });
}
_chunk7QVYU63Ejs.__name.call(void 0, createMockErrorResponse, "createMockErrorResponse");

// src/testing/factories/createMockService.ts
var _vitest = require('vitest');
function createMockService(options = {}) {
  const defaultResponse = _nullishCoalesce(options.defaultResponse, () => ( createMockResponse({ ok: true })));
  return {
    get: _vitest.vi.fn().mockResolvedValue(defaultResponse),
    post: _vitest.vi.fn().mockResolvedValue(defaultResponse),
    put: _vitest.vi.fn().mockResolvedValue(defaultResponse),
    patch: _vitest.vi.fn().mockResolvedValue(defaultResponse),
    delete: _vitest.vi.fn().mockResolvedValue(defaultResponse)
  };
}
_chunk7QVYU63Ejs.__name.call(void 0, createMockService, "createMockService");
function createMockErrorService(statusCode = 500, errorMessage = "Error") {
  const errorResponse = createMockResponse({
    ok: false,
    response: statusCode,
    error: errorMessage
  });
  return {
    get: _vitest.vi.fn().mockResolvedValue(errorResponse),
    post: _vitest.vi.fn().mockResolvedValue(errorResponse),
    put: _vitest.vi.fn().mockResolvedValue(errorResponse),
    patch: _vitest.vi.fn().mockResolvedValue(errorResponse),
    delete: _vitest.vi.fn().mockResolvedValue(errorResponse)
  };
}
_chunk7QVYU63Ejs.__name.call(void 0, createMockErrorService, "createMockErrorService");

// src/testing/factories/createMockApiData.ts
function createMockApiData(options) {
  const {
    type,
    id = `mock-${type}-${Math.random().toString(36).substring(7)}`,
    attributes = {},
    relationships = {},
    included = [],
    createdAt = /* @__PURE__ */ new Date(),
    updatedAt = /* @__PURE__ */ new Date(),
    self
  } = options;
  const jsonApiData = {
    type,
    id,
    attributes: {
      ...attributes,
      createdAt: createdAt.toISOString(),
      updatedAt: updatedAt.toISOString()
    },
    relationships
  };
  const mockData = {
    get included() {
      return included;
    },
    get type() {
      return type;
    },
    get id() {
      return id;
    },
    get createdAt() {
      return createdAt;
    },
    get updatedAt() {
      return updatedAt;
    },
    get self() {
      return self;
    },
    get jsonApi() {
      return jsonApiData;
    },
    generateApiUrl: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (params) => {
      const baseUrl = `/${type}/${id}`;
      if (params) {
        const searchParams = new URLSearchParams(params);
        return `${baseUrl}?${searchParams.toString()}`;
      }
      return baseUrl;
    }, "generateApiUrl"),
    dehydrate: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => ({
      jsonApi: jsonApiData,
      included,
      allData: [jsonApiData]
    }), "dehydrate"),
    rehydrate: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, function(_data) {
      return this;
    }, "rehydrate"),
    createJsonApi: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (data) => ({
      type,
      id,
      attributes: data
    }), "createJsonApi")
  };
  Object.keys(attributes).forEach((key) => {
    Object.defineProperty(mockData, key, {
      get: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => attributes[key], "get"),
      enumerable: true
    });
  });
  return mockData;
}
_chunk7QVYU63Ejs.__name.call(void 0, createMockApiData, "createMockApiData");
function createMockApiDataList(type, count, attributesFactory) {
  return Array.from(
    { length: count },
    (_, index) => createMockApiData({
      type,
      id: `${index + 1}`,
      attributes: _nullishCoalesce(_optionalChain([attributesFactory, 'optionalCall', _2 => _2(index)]), () => ( {}))
    })
  );
}
_chunk7QVYU63Ejs.__name.call(void 0, createMockApiDataList, "createMockApiDataList");

// src/testing/matchers/jsonApiMatchers.ts

var jsonApiMatchers = {
  /**
   * Asserts that the response has a valid JSON:API structure with type and id.
   */
  toBeValidJsonApi(received) {
    const data = Array.isArray(_optionalChain([received, 'optionalAccess', _3 => _3.data])) ? received.data[0] : _optionalChain([received, 'optionalAccess', _4 => _4.data]);
    const hasType = typeof _optionalChain([data, 'optionalAccess', _5 => _5.type]) === "string" && data.type.length > 0;
    const hasId = typeof _optionalChain([data, 'optionalAccess', _6 => _6.id]) === "string" && data.id.length > 0;
    const isValid = hasType && hasId;
    return {
      pass: isValid,
      message: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => isValid ? `Expected response not to be valid JSON:API, but it has type "${_optionalChain([data, 'optionalAccess', _7 => _7.type])}" and id "${_optionalChain([data, 'optionalAccess', _8 => _8.id])}"` : `Expected response to be valid JSON:API with type and id, but got type: ${JSON.stringify(_optionalChain([data, 'optionalAccess', _9 => _9.type]))}, id: ${JSON.stringify(_optionalChain([data, 'optionalAccess', _10 => _10.id]))}`, "message")
    };
  },
  /**
   * Asserts that the response data has the expected JSON:API type.
   */
  toHaveJsonApiType(received, expectedType) {
    const data = Array.isArray(_optionalChain([received, 'optionalAccess', _11 => _11.data])) ? received.data[0] : _optionalChain([received, 'optionalAccess', _12 => _12.data]);
    const actualType = _optionalChain([data, 'optionalAccess', _13 => _13.type]);
    const pass = actualType === expectedType;
    return {
      pass,
      message: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => pass ? `Expected response not to have JSON:API type "${expectedType}"` : `Expected response to have JSON:API type "${expectedType}", but got "${actualType}"`, "message")
    };
  },
  /**
   * Asserts that the response data has an attribute with the expected value.
   */
  toHaveJsonApiAttribute(received, attributeName, expectedValue) {
    const data = Array.isArray(_optionalChain([received, 'optionalAccess', _14 => _14.data])) ? received.data[0] : _optionalChain([received, 'optionalAccess', _15 => _15.data]);
    const attributes = _nullishCoalesce(_optionalChain([data, 'optionalAccess', _16 => _16.attributes]), () => ( {}));
    const hasAttribute = attributeName in attributes;
    const actualValue = attributes[attributeName];
    if (expectedValue === void 0) {
      return {
        pass: hasAttribute,
        message: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => hasAttribute ? `Expected response not to have JSON:API attribute "${attributeName}"` : `Expected response to have JSON:API attribute "${attributeName}", but it was not found. Available attributes: ${Object.keys(attributes).join(", ") || "none"}`, "message")
      };
    }
    const valuesMatch = actualValue === expectedValue;
    return {
      pass: hasAttribute && valuesMatch,
      message: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => hasAttribute && valuesMatch ? `Expected response not to have JSON:API attribute "${attributeName}" with value "${expectedValue}"` : !hasAttribute ? `Expected response to have JSON:API attribute "${attributeName}", but it was not found` : `Expected JSON:API attribute "${attributeName}" to be "${expectedValue}", but got "${actualValue}"`, "message")
    };
  },
  /**
   * Asserts that the response data has the specified relationship.
   */
  toHaveJsonApiRelationship(received, relationshipName) {
    const data = Array.isArray(_optionalChain([received, 'optionalAccess', _17 => _17.data])) ? received.data[0] : _optionalChain([received, 'optionalAccess', _18 => _18.data]);
    const relationships = _nullishCoalesce(_optionalChain([data, 'optionalAccess', _19 => _19.relationships]), () => ( {}));
    const hasRelationship = relationshipName in relationships;
    return {
      pass: hasRelationship,
      message: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => hasRelationship ? `Expected response not to have JSON:API relationship "${relationshipName}"` : `Expected response to have JSON:API relationship "${relationshipName}", but it was not found. Available relationships: ${Object.keys(relationships).join(", ") || "none"}`, "message")
    };
  },
  /**
   * Asserts that the response data array has the expected length.
   */
  toHaveJsonApiLength(received, expectedLength) {
    const data = _optionalChain([received, 'optionalAccess', _20 => _20.data]);
    const isArray = Array.isArray(data);
    const actualLength = isArray ? data.length : data ? 1 : 0;
    const pass = actualLength === expectedLength;
    return {
      pass,
      message: /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => pass ? `Expected response not to have ${expectedLength} items` : `Expected response to have ${expectedLength} items, but got ${actualLength}`, "message")
    };
  }
};
function extendExpectWithJsonApiMatchers() {
  _vitest.expect.extend(jsonApiMatchers);
}
_chunk7QVYU63Ejs.__name.call(void 0, extendExpectWithJsonApiMatchers, "extendExpectWithJsonApiMatchers");

// src/testing/utils/renderWithProviders.tsx
var _react = require('@testing-library/react');

var _userevent = require('@testing-library/user-event');

function renderWithProviders(ui, options = {}) {
  const { jsonApiConfig, wrapper: AdditionalWrapper, ...renderOptions } = options;
  function AllProviders({ children }) {
    const content = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MockJsonApiProvider, { config: jsonApiConfig, children });
    if (AdditionalWrapper) {
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AdditionalWrapper, { children: content });
    }
    return content;
  }
  _chunk7QVYU63Ejs.__name.call(void 0, AllProviders, "AllProviders");
  return _react.render.call(void 0, ui, { wrapper: AllProviders, ...renderOptions });
}
_chunk7QVYU63Ejs.__name.call(void 0, renderWithProviders, "renderWithProviders");



















exports.MockJsonApiProvider = MockJsonApiProvider; exports.createMockApiData = createMockApiData; exports.createMockApiDataList = createMockApiDataList; exports.createMockErrorResponse = createMockErrorResponse; exports.createMockErrorService = createMockErrorService; exports.createMockModule = createMockModule; exports.createMockResponse = createMockResponse; exports.createMockService = createMockService; exports.defaultMockConfig = defaultMockConfig; exports.extendExpectWithJsonApiMatchers = extendExpectWithJsonApiMatchers; exports.fireEvent = _react.fireEvent; exports.jsonApiMatchers = jsonApiMatchers; exports.render = _react.render; exports.renderWithProviders = renderWithProviders; exports.screen = _react.screen; exports.userEvent = _userevent.userEvent; exports.waitFor = _react.waitFor; exports.within = _react.within;
//# sourceMappingURL=index.js.map