SPB Git

Repository Public

LiveTests.swift 9.4 KB 184 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Lou-Ka iOS9// File             : LouKaTests/LiveTests.swift10// Description      : contrat réel de l'API publique (lecture seule) — ce que11//                    lisent l'app, les widgets et les raccourcis. Ces tests12//                    exigent le réseau ; ils échouent si le serveur change de13//                    forme.14// Module           : LouKaTests15// Repository       : https://git.spboucher.ai/lou-ka-ios-v316// Project Website  : https://www.lou-ka.com17// Created          : 2026-11-2818// Last Modified    : 2026-11-2819//20// =============================================================================21// AUTHOR & PROFESSIONAL AFFILIATION22// =============================================================================23//24// Author           : Simon-Pierre Boucher25// Position         : Professor of Finance26// Institution      : Université du Québec en Outaouais (UQO)27// Department       : Département des sciences administratives28// Organization     : SP Boucher29//30// Website          : https://spboucher.ai31// Git              : https://git.spboucher.ai32//33// =============================================================================34// OFFICIAL CONTACT DIRECTORY35// =============================================================================36//37// General          : info@spboucher.ai38// Professional     : contact@spboucher.ai39// Direct           : simon@spboucher.ai40// Research         : research@spboucher.ai41// Development      : dev@spboucher.ai42// Support          : support@spboucher.ai43// Security/Admin   : admin@spboucher.ai44// Notifications    : notifications@spboucher.ai45//46// Preferred Contact: support@spboucher.ai47//48// =============================================================================49// COPYRIGHT & INTELLECTUAL PROPERTY50// =============================================================================51//52// Copyright (c) 202653// Simon-Pierre Boucher54//55// All rights reserved where applicable.56//57// This file is governed by the applicable project license,58// copyright notices, institutional agreements and relevant law.59//60// Unless expressly authorized by the applicable license or61// rights holder, copying, redistribution, sublicensing,62// publication and commercial exploitation are not permitted.63//64// Existing third-party rights and notices remain unaffected.65//66// =============================================================================67// CONFIDENTIALITY & SECURITY68// =============================================================================69//70// Classification   : Public71// Distribution     : Public repository; use is governed by the project license72// Security Contact : admin@spboucher.ai73//74// Access to this source does not independently grant permission75// to redistribute or disclose confidential materials.76//77// Do not embed credentials, private keys, access tokens,78// certificates or confidential personal information.79//80// =============================================================================81// LICENSE & MAINTENANCE82// =============================================================================83//84// License          : None specified (no license file in this repository)85// Maintainer       : Simon-Pierre Boucher86// Technical Contact: dev@spboucher.ai87//88// =============================================================================89// END OF SP BOUCHER SOURCE HEADER90// =============================================================================9192import Foundation93import Testing94@testable import LouKa9596@Suite("API de production (réseau)", .serialized)97struct LiveTests {98    @Test("version, recherche par curseur sans doublon, carte, compteurs")99    func searchContract() async throws {100        let api = APIClient.shared101        let v = try await api.v3Version()102        #expect(v.api == 3 && (v.listings ?? 0) > 1000)103        var f = SearchFilters(); f.city = "Montréal"; f.rooms = [4]104        let p1 = try await api.search(f, sort: .prix, limit: 20)105        #expect(p1.total > 100 && p1.items.count == 20 && p1.nextCursor != nil)106        #expect(p1.items.allSatisfy { $0.rooms == 4 }, "le filtre de grandeur est respecté")107        #expect(zip(p1.items, p1.items.dropFirst()).allSatisfy { ($0.price ?? 0) <= ($1.price ?? 0) }, "tri par loyer croissant")108        let p2 = try await api.search(f, sort: .prix, cursor: p1.nextCursor, limit: 20)109        #expect(Set(p1.items.map(\.uid)).isDisjoint(with: p2.items.map(\.uid)), "la page suivante ne répète aucune annonce")110        let facets = try await api.searchFacets(f)111        #expect(facets.total == p1.total && facets.rooms[4] == p1.total)112        let wide = try await api.searchMap(SearchFilters(), bbox: "-74.2,45.3,-73.3,45.8", zoom: 9)113        #expect(wide.isClustered && wide.clusters.reduce(0) { $0 + $1.count } == wide.total)114        let near = try await api.searchMap(f, bbox: "-73.60,45.51,-73.57,45.53", zoom: 15)115        #expect(!near.isClustered && near.points.count == near.total)116    }117118    @Test("phrase libre → filtres → résultats")119    func phrase() async throws {120        let p = try await APIClient.shared.parse(phrase: "4½ à Québec sous 1 500 $ avec balcon")121        var f = SearchFilters()122        let unknown = f.apply(params: p.params)123        #expect(unknown.isEmpty && f.city == "Québec" && f.rooms == [4] && f.priceMax == 1500 && f.features == ["balcony"])124        let r = try await APIClient.shared.search(f, limit: 10)125        #expect(r.total > 0 && r.items.allSatisfy { ($0.price ?? 0) <= 1500 && $0.features["balcony"] == true })126    }127128    @Test("fiche : analyses v3 d'une annonce réelle, erreurs structurées")129    func listing() async throws {130        let api = APIClient.shared131        var f = SearchFilters(); f.city = "Montréal"; f.deal = .marche132        let l = try #require(try await api.search(f, limit: 5).items.first)133        let full = try await api.listingV3(l.uid)134        #expect(full.uid == l.uid && !full.images.isEmpty)135        let v = try await api.valuation(l.uid)136        #expect(v.low < v.estimate && v.estimate < v.high && v.verdict == .marche && !v.limits.isEmpty)137        let tc = try await api.trueCost(l.uid)138        #expect(tc.lines.first?.key == "rent" && tc.monthly?.amount != nil)139        var a = CostAssumptions(); a.values["internet"] = 65140        let tc2 = try await api.trueCost(l.uid, assumptions: a)141        let internet = try #require(tc2.lines.first { $0.key == "internet" })142        #expect(internet.status == "saisi" || internet.status == "inclus", "le montant saisi est repris, sauf si Internet est inclus")143        _ = try await api.comparables(l.uid, k: 3)144        _ = try await api.links(l.uid)145        await #expect(throws: APIError.self) { _ = try await api.listingV3("inconnu:0") }146        do { _ = try await api.listingV3("inconnu:0") } catch let e as APIError { #expect(e.code == "not_found") }147        // deuxième lecture : la copie locale est validée par ETag (304) ou servie par le cache du système148        let before = await api.sessionStats()149        _ = try await api.valuation(l.uid)150        let after = await api.sessionStats()151        #expect(after.fetched + after.notModified >= before.fetched + before.notModified)152    }153154    @Test("marché, indice, quartiers")155    func market() async throws {156        let api = APIClient.shared157        let qc = try await api.market()158        #expect(qc.current["rent_median"]?.value != nil && qc.month?.const["rent_median"] != nil)159        let place = try #require(try await api.suggestPlaces("montreal").first { $0.kind == "municipalite" })160        let m = try await api.market(place: place, rooms: 4)161        #expect(m.place?.slug == "montreal" && m.roomsLabel == "4½")162        #expect(try await api.marketSeries(place: place).points.count >= 3)163        #expect(try await api.marketIndex().published)164        let hoods = try await api.neighborhoods(city: "montreal", sort: "score", weights: ["walk": 1, "transit": 0, "bike": 0, "calme": 0, "services": 0])165        #expect(hoods.items.count > 5)166        #expect(zip(hoods.items, hoods.items.dropFirst()).allSatisfy { ($0.score ?? 0) >= ($1.score ?? 0) }, "le tri par score applique les pondérations")167        let portrait = try await api.neighborhood(slug: hoods.items[0].slug, city: "montreal")168        #expect(portrait.listings != nil && !portrait.scores.isEmpty)169    }170171    @Test("widgets et raccourcis : lecture partagée")172    func shared() async throws {173        let top = try await SharedAPI.topPlaces()174        let mtl = try #require(top.first { $0.slug == "montreal" })175        let news = try await SharedAPI.newListings(place: mtl, rooms: 4)176        #expect(news.total >= news.items.count && news.items.allSatisfy { $0.unit == "4½" && $0.place.contains("Montréal") })177        #expect(news.items.first.map { DeepLink(url: $0.url) == .listing($0.uid) } ?? true, "une ligne du widget ouvre sa fiche")178        let brief = try await SharedAPI.market(place: mtl)179        #expect(brief.placeName == "Montréal" && brief.median != nil && brief.active != nil && brief.currentMonth != nil)180        let hits = try await PlaceQuery().entities(matching: "rosem")181        #expect(hits.contains { $0.name.hasPrefix("Rosemont") })182    }183}184
Files main
Menu

Theme