bulk-questionnaire-upload/tests/frontend/form.service.spec.ts
vee1e 165b249c3d feat: implement CI workflow, enhance file validation, and add test cases
- Introduced a CI workflow for automated testing of backend and frontend components.
- Added pytest configuration for backend tests and Vitest configuration for frontend tests.
- Enhanced file validation logic in the backend to improve error handling and reporting.
- Created comprehensive test cases for various validation scenarios, including edge cases and incorrect formats.
- Updated requirements to include necessary testing libraries and tools.
2025-08-26 00:22:54 +05:30

59 lines
1.6 KiB
TypeScript

import type { HttpClient } from '@angular/common/http'
import { describe, it, expect, vi } from 'vitest'
function of<T>(value: T) {
return {
subscribe: (next?: (v: T) => void) => {
if (typeof next === 'function') next(value)
return { unsubscribe() {} }
}
} as any
}
import { FormService } from '../../frontend/src/app/services/form.service'
class HttpClientStub {
post<T>(url: string, body: any) {
return of({} as T)
}
get<T>(url: string) {
return of({} as T)
}
delete<T>(url: string) {
return of({} as T)
}
put<T>(url: string, body: any) {
return of({} as T)
}
}
describe('FormService', () => {
let service: FormService
beforeEach(() => {
service = new FormService(new HttpClientStub() as unknown as HttpClient)
})
it('should call validate endpoint', async () => {
const file = new Blob(['a']) as any
const spy = vi.spyOn(HttpClientStub.prototype, 'post')
service.validateFile(file).subscribe()
expect(spy).toHaveBeenCalled()
expect(spy.mock.calls[0][0]).toContain('/api/validate')
})
it('should call parse endpoint', async () => {
const file = new Blob(['a']) as any
const spy = vi.spyOn(HttpClientStub.prototype, 'post')
service.parseFile(file).subscribe()
expect(spy).toHaveBeenCalled()
expect(spy.mock.calls[0][0]).toContain('/api/forms/parse')
})
it('should call getAllForms endpoint', async () => {
const spy = vi.spyOn(HttpClientStub.prototype, 'get')
service.getAllForms().subscribe()
expect(spy).toHaveBeenCalled()
expect(spy.mock.calls[0][0]).toContain('/api/forms')
})
})