// app-store.test.js

import AppStore from '../app-store';
import jest from 'jest'
import mockAxios from 'jest-mock-axios';

describe('AppStore', () => {
  let appStore;

  beforeEach(() => {
    appStore = new AppStore();
  });

  describe('getStoreInfo', () => {
    const mockStoreData = {
      name: 'My Store',
      address: '123 Main St',
      phone: '555-1234',
    };

    const mockFetchStoreInfo = jest.fn().mockReturnValue(mockStoreData);

    beforeEach(() => {
      appStore.fetchStoreInfo = mockFetchStoreInfo;
      mockAxios.reset();
    });

    it('should call fetchStoreInfo to retrieve store data', async () => {
      await appStore.getStoreInfo();

      expect(mockFetchStoreInfo).toHaveBeenCalled();
    });

    it('should return store data when fetchStoreInfo succeeds', async () => {
      const storeInfo = await appStore.getStoreInfo();

      expect(storeInfo).toEqual(mockStoreData);
    });

    it('should throw an error when fetchStoreInfo fails', async () => {
      const mockError = new Error('Failed to fetch store info');
      mockFetchStoreInfo.mockRejectedValue(mockError);

      await expect(appStore.getStoreInfo()).rejects.toThrow(mockError);
    });
  });
});