super-productivity/debug-headers.spec.ts
Johannes Millan 8238606f46 feat(webdav): add comprehensive Last-Modified fallback support
- Implements robust WebDAV sync for servers without ETag support
- Adds _extractValidators method for ETag and Last-Modified headers
- Enhances conditional header creation with Last-Modified support
- Adds LOCK/UNLOCK mechanism for safe resource creation
- Implements server capability detection with caching
- Adds NoRevAPIError retry mechanism for missing validators
- Includes comprehensive test coverage for all workflows
- Maintains backward compatibility with existing ETag-based code

This enables WebDAV sync with basic servers that only support
Last-Modified headers while preserving optimal performance
for servers with full ETag support.
2025-07-18 12:11:05 +02:00

46 lines
No EOL
1.3 KiB
TypeScript

import { WebdavApi } from './src/app/pfapi/api/sync/providers/webdav/webdav-api';
import { WebdavPrivateCfg } from './src/app/pfapi/api/sync/providers/webdav/webdav';
import { createMockResponse } from './src/app/pfapi/api/sync/providers/webdav/webdav-api-test-utils';
describe('Debug Headers', () => {
let mockFetch: jasmine.Spy;
let api: WebdavApi;
const mockConfig: WebdavPrivateCfg = {
baseUrl: 'https://webdav.example.com',
userName: 'testuser',
password: 'testpass',
syncFolderPath: '/sync',
serverCapabilities: {
supportsETags: true,
supportsLastModified: false,
supportsIfHeader: true,
supportsLocking: false,
},
};
beforeEach(() => {
mockFetch = spyOn(globalThis, 'fetch');
api = new WebdavApi(async () => mockConfig);
});
it('should set If-None-Match for new file creation', async () => {
const uploadResponse = createMockResponse(201, {
etag: '"v1"',
});
mockFetch.and.callFake((url, options) => {
console.log('Called with:', url, JSON.stringify(options));
return Promise.resolve(uploadResponse);
});
const result = await api.upload({
path: '/test.txt',
data: 'content',
isOverwrite: false,
});
expect(result).toBe('v1');
expect(mockFetch).toHaveBeenCalled();
});
});