@applica-software-guru/crud-client
Version:
Libreria per l'accesso ai servizi REST di Applica.
69 lines (61 loc) • 2.45 kB
text/typescript
import { PASSWORD, USERNAME, createProviders } from './config';
import { describe, expect, it } from 'vitest';
describe('test timeout', async () => {
const { dataProvider, authProvider } = createProviders(30000); // Use default 30s for provider
it('should throw timeout after 50ms when specified per request', async () => {
await authProvider.login({ username: USERNAME, password: PASSWORD });
await expect(
dataProvider.getList('entities/category', {
pagination: {
page: 1,
perPage: 10
},
sort: {
field: 'id',
order: 'ASC'
},
timeout: 50 // Override timeout to 50ms for this specific request
})
).rejects.toThrow('error.request_timeout');
});
it('should use default timeout when not specified in request', async () => {
await authProvider.login({ username: USERNAME, password: PASSWORD });
// This should use the provider's default timeout (30 seconds from config)
// Since this is a real test against localhost, it may succeed or fail depending on server
try {
await dataProvider.getList('entities/category', {
pagination: {
page: 1,
perPage: 10
},
sort: {
field: 'id',
order: 'ASC'
}
// No timeout specified - should use default 30000ms from provider config
});
} catch (error: any) {
// If it fails, it should not be due to timeout (unless server really takes >30s)
if (error.message === 'error.request_timeout') {
throw new Error('Request timed out with default timeout - server might be too slow');
}
// Other errors are acceptable (server down, network issues, etc.)
}
});
it('should allow different timeouts for different requests', async () => {
await authProvider.login({ username: USERNAME, password: PASSWORD });
// Test multiple requests with different timeouts
const requests = [
dataProvider.getOne('entities/category', { id: 1, timeout: 25 }),
dataProvider.getMany('entities/category', { ids: [1, 2], timeout: 30 }),
dataProvider.create('entities/category', {
data: { description: { it: 'Test Category' } },
timeout: 35
})
];
// All should timeout due to very short timeout values
for (const request of requests) {
await expect(request).rejects.toThrow('error.request_timeout');
}
});
});