import * as __WEBPACK_EXTERNAL_MODULE_axios__ from "axios";
import * as __WEBPACK_EXTERNAL_MODULE__APIClient_mjs__ from "../APIClient.mjs";
describe('APIClient', ()=>{
    describe('axios', ()=>{
        it('case 1', ()=>{
            const apiClient = new __WEBPACK_EXTERNAL_MODULE__APIClient_mjs__.APIClient();
            expect(apiClient.axios).toBeDefined();
            expect(typeof apiClient.axios).toBe('function');
            expect(typeof apiClient.axios.request).toBe('function');
        });
        it('case 2', ()=>{
            const apiClient = new __WEBPACK_EXTERNAL_MODULE__APIClient_mjs__.APIClient({
                baseURL: 'http://localhost/api/'
            });
            expect(apiClient.axios.defaults.baseURL).toBe('http://localhost/api/');
        });
        it('case 3', ()=>{
            const instance = __WEBPACK_EXTERNAL_MODULE_axios__["default"].create();
            const apiClient = new __WEBPACK_EXTERNAL_MODULE__APIClient_mjs__.APIClient(instance);
            expect(apiClient.axios).toBe(instance);
        });
    });
    test('should reset role when role is not found', async ()=>{
        const instance = __WEBPACK_EXTERNAL_MODULE_axios__["default"].create();
        instance.interceptors.response.use((response)=>response, (error)=>{
            error = {
                response: {
                    data: {
                        errors: [
                            {
                                code: 'ROLE_NOT_FOUND_ERR'
                            }
                        ]
                    }
                }
            };
            throw error;
        });
        const apiClient = new __WEBPACK_EXTERNAL_MODULE__APIClient_mjs__.APIClient(instance);
        apiClient.app = {};
        apiClient.auth.setRole('not-found');
        expect(apiClient.auth.role).toBe('not-found');
        try {
            await apiClient.request({
                method: 'GET',
                url: '/api/test'
            });
        } catch (err) {
            console.log(err);
            expect(err).toBeDefined();
            expect(err.response.data.errors[0].code).toBe('ROLE_NOT_FOUND_ERR');
        }
        expect(apiClient.auth.role).toBeFalsy();
    });
});
