FakeAilianceApi.swift
243 lignes · 10701 octets
import Foundation @testable import Card2vcf /// Configurable fake `AilianceApi`; everything answers empty Ok by default. /// Shared by `SyncEngineTest` and `AgendaSyncEngineTest`. final class FakeAilianceApi: AilianceApi { var statusResult: AilianceApiClient.ApiResult<SyncStatusResponse> = .ok(SyncStatusResponse(serverTime: "1970-01-01T00:00:00Z", changes: SyncChanges(), total: 0)) var pullResult: AilianceApiClient.ApiResult<SyncPullResponse> = .ok(SyncPullResponse(serverTime: "1970-01-01T00:00:00Z")) var createContactResult: AilianceApiClient.ApiResult<String> = .ok(#"{"id":"srv-generated"}"#) var createContactCalls: [String] = [] var createReservationResult: AilianceApiClient.ApiResult<String> = .ok(#"{"id":"resa-generated"}"#) var updateReservationResult: AilianceApiClient.ApiResult<String> = .ok("{}") var createReservationCalls: [(String, String, String)] = [] var deleteReservationCalls: [(String, String, String)] = [] var createRdvResult: AilianceApiClient.ApiResult<String> = .ok(#"{"id":"rdv-generated"}"#) var createRdvCalls: [String] = [] var createProjetResult: AilianceApiClient.ApiResult<String> = .ok(#"{"id":"projet-generated"}"#) var createProjetCalls: [String] = [] /// `(projetId, tacheId, sousTacheId)` de chaque bascule de sous-tâche poussée. var toggleSousTacheCalls: [(String, String, String)] = [] var statusQueries: [String?] = [] var pullQueries: [String?] = [] var pullSince: [String] = [] var uploadCarteResult: AilianceApiClient.ApiResult<String> = .ok("{}") var uploadPhotoResult: AilianceApiClient.ApiResult<String> = .ok("{}") var uploadCarteCalls: [(String, Int)] = [] var uploadPhotoCalls: [(String, Int)] = [] var downloadCarteResult: AilianceApiClient.ApiResult<Data> = .err(code: 404, message: "absent") var downloadPhotoResult: AilianceApiClient.ApiResult<Data> = .err(code: 404, message: "absent") var downloadCarteCalls: [String] = [] var downloadPhotoCalls: [String] = [] func authCle(nom: String, motDePasse: String) async -> AilianceApiClient.ApiResult<AuthCleResponse> { .ok(AuthCleResponse(nom: nom, cleChiffree: "", sel: "", kdf: "argon2id", cipher: "xchacha20poly1305")) } func syncStatus(sinceIso: String, ressourcesQuery: String?) async -> AilianceApiClient.ApiResult<SyncStatusResponse> { statusQueries.append(ressourcesQuery) return statusResult } func syncPull(sinceIso: String, ressourcesQuery: String?) async -> AilianceApiClient.ApiResult<SyncPullResponse> { pullQueries.append(ressourcesQuery) pullSince.append(sinceIso) return pullResult } func createContact(jsonBody: String) async -> AilianceApiClient.ApiResult<String> { createContactCalls.append(jsonBody) return createContactResult } func updateContact(id: String, jsonBody: String) async -> AilianceApiClient.ApiResult<String> { .ok("{}") } func deleteContact(id: String) async -> AilianceApiClient.ApiResult<Void> { .ok(()) } func createEntreprise(jsonBody: String) async -> AilianceApiClient.ApiResult<String> { .ok("{}") } func updateEntreprise(id: String, jsonBody: String) async -> AilianceApiClient.ApiResult<String> { .ok("{}") } func deleteEntreprise(id: String) async -> AilianceApiClient.ApiResult<Void> { .ok(()) } func createProjet(jsonBody: String) async -> AilianceApiClient.ApiResult<String> { createProjetCalls.append(jsonBody) return createProjetResult } func updateProjet(id: String, jsonBody: String) async -> AilianceApiClient.ApiResult<String> { .ok("{}") } func deleteProjet(id: String) async -> AilianceApiClient.ApiResult<Void> { .ok(()) } func createTache(projetId: String, jsonBody: String) async -> AilianceApiClient.ApiResult<String> { .ok("{}") } func updateTache(projetId: String, tacheId: String, jsonBody: String) async -> AilianceApiClient.ApiResult<String> { .ok("{}") } func deleteTache(projetId: String, tacheId: String) async -> AilianceApiClient.ApiResult<Void> { .ok(()) } func moveTache(projetId: String, tacheId: String, jsonBody: String) async -> AilianceApiClient.ApiResult<String> { .ok("{}") } func toggleSousTache( projetId: String, tacheId: String, sousTacheId: String ) async -> AilianceApiClient.ApiResult<String> { toggleSousTacheCalls.append((projetId, tacheId, sousTacheId)) return .ok("{}") } func createInteraction(contactId: String, jsonBody: String) async -> AilianceApiClient.ApiResult<String> { .ok("{}") } func listRdv() async -> AilianceApiClient.ApiResult<[RendezVousDto]> { .ok([]) } func createRdv(jsonBody: String) async -> AilianceApiClient.ApiResult<String> { createRdvCalls.append(jsonBody) return createRdvResult } func getRdv(id: String) async -> AilianceApiClient.ApiResult<RendezVousDto> { fatalError("not used") } func updateRdv(id: String, jsonBody: String) async -> AilianceApiClient.ApiResult<String> { .ok("{}") } func deleteRdv(id: String) async -> AilianceApiClient.ApiResult<Void> { .ok(()) } func getRessourcesCatalogue() async -> AilianceApiClient.ApiResult<RessourcesCatalogueDto> { .ok(RessourcesCatalogueDto()) } func listReservations(genre: String, resourceId: String) async -> AilianceApiClient.ApiResult<[ReservationDto]> { .ok([]) } func createReservation(genre: String, resourceId: String, jsonBody: String) async -> AilianceApiClient.ApiResult<String> { createReservationCalls.append((genre, resourceId, jsonBody)) return createReservationResult } func updateReservation( genre: String, resourceId: String, reservationId: String, jsonBody: String ) async -> AilianceApiClient.ApiResult<String> { updateReservationResult } func deleteReservation(genre: String, resourceId: String, reservationId: String) async -> AilianceApiClient.ApiResult<Void> { deleteReservationCalls.append((genre, resourceId, reservationId)) return .ok(()) } func listIndisponibilites(genre: String, resourceId: String) async -> AilianceApiClient.ApiResult<[IndisponibiliteDto]> { .ok([]) } func uploadContactCarte( id: String, bytes: Data, filename: String, contentType: String ) async -> AilianceApiClient.ApiResult<String> { uploadCarteCalls.append((id, bytes.count)) return uploadCarteResult } func uploadContactPhoto( id: String, bytes: Data, filename: String, contentType: String ) async -> AilianceApiClient.ApiResult<String> { uploadPhotoCalls.append((id, bytes.count)) return uploadPhotoResult } func downloadContactCarte(id: String) async -> AilianceApiClient.ApiResult<Data> { downloadCarteCalls.append(id) return downloadCarteResult } func downloadContactPhoto(id: String) async -> AilianceApiClient.ApiResult<Data> { downloadPhotoCalls.append(id) return downloadPhotoResult } var uploadInteractionAudioResult: AilianceApiClient.ApiResult<String> = .ok("{}") /// (contactId, interactionId, bytes.count) var uploadInteractionAudioCalls: [(String, String, Int)] = [] var downloadInteractionAudioResult: AilianceApiClient.ApiResult<Data> = .err(code: 404, message: "absent") func uploadInteractionAudio( contactId: String, interactionId: String, bytes: Data, filename: String ) async -> AilianceApiClient.ApiResult<String> { uploadInteractionAudioCalls.append((contactId, interactionId, bytes.count)) return uploadInteractionAudioResult } func downloadInteractionAudio(contactId: String, interactionId: String) async -> AilianceApiClient.ApiResult<Data> { downloadInteractionAudioResult } var createNoteProjetResult: AilianceApiClient.ApiResult<String> = .ok(#"{"id":"note-generated"}"#) /// (projetId, jsonBody) var createNoteProjetCalls: [(String, String)] = [] func createNoteProjet(projetId: String, jsonBody: String) async -> AilianceApiClient.ApiResult<String> { createNoteProjetCalls.append((projetId, jsonBody)) return createNoteProjetResult } var uploadNoteProjetAudioResult: AilianceApiClient.ApiResult<String> = .ok("{}") /// (projetId, noteId, bytes.count) var uploadNoteProjetAudioCalls: [(String, String, Int)] = [] var downloadNoteProjetAudioResult: AilianceApiClient.ApiResult<Data> = .err(code: 404, message: "absent") func uploadNoteProjetAudio( projetId: String, noteId: String, bytes: Data, filename: String ) async -> AilianceApiClient.ApiResult<String> { uploadNoteProjetAudioCalls.append((projetId, noteId, bytes.count)) return uploadNoteProjetAudioResult } func downloadNoteProjetAudio(projetId: String, noteId: String) async -> AilianceApiClient.ApiResult<Data> { downloadNoteProjetAudioResult } var deleteInteractionResult: AilianceApiClient.ApiResult<Void> = .ok(()) var deleteInteractionCalls: [String] = [] func deleteInteraction(interactionId: String) async -> AilianceApiClient.ApiResult<Void> { deleteInteractionCalls.append(interactionId) return deleteInteractionResult } var deleteNoteProjetResult: AilianceApiClient.ApiResult<Void> = .ok(()) /// (projetId, noteId) var deleteNoteProjetCalls: [(String, String)] = [] func deleteNoteProjet(projetId: String, noteId: String) async -> AilianceApiClient.ApiResult<Void> { deleteNoteProjetCalls.append((projetId, noteId)) return deleteNoteProjetResult } var relancerInteractionResult: AilianceApiClient.ApiResult<String> = .ok("{}") /// (contactId, interactionId) var relancerInteractionCalls: [(String, String)] = [] func relancerTranscriptionInteraction( contactId: String, interactionId: String ) async -> AilianceApiClient.ApiResult<String> { relancerInteractionCalls.append((contactId, interactionId)) return relancerInteractionResult } var relancerNoteProjetResult: AilianceApiClient.ApiResult<String> = .ok("{}") /// (projetId, noteId) var relancerNoteProjetCalls: [(String, String)] = [] func relancerTranscriptionNoteProjet( projetId: String, noteId: String ) async -> AilianceApiClient.ApiResult<String> { relancerNoteProjetCalls.append((projetId, noteId)) return relancerNoteProjetResult } }
GitRust