Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Vrai-Prix iOS9// File : VraiPrixTests/ContractTests.swift10// Description : contrat avec la production (www.vrai-prix.com), en lecture11// seule : ce que lisent les widgets et les raccourcis, et la12// sonde du niveau. Valables que la production serve l'API 213// seule ou aussi l'API v3.14// Module : VraiPrixTests15// Repository : https://git.spboucher.ai/vrai-prix-ios-v316// Project Website : https://www.vrai-prix.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 XCTest93@testable import VraiPrix9495final class ContractTests: XCTestCase {96 func testMunicipalitiesForWidgetsAndShortcuts() async throws {97 let all = try await SharedAPI.municipalities(matching: nil)98 XCTAssertGreaterThan(all.count, 1000)99 XCTAssertEqual(all.first?.slug, "montreal", "les plus peuplées d'abord")100 let hits = try await SharedAPI.municipalities(matching: "sherb")101 XCTAssertEqual(hits.first?.name, "Sherbrooke")102 let e = try XCTUnwrap(hits.first.map(PlaceEntity.init))103 XCTAssertEqual(PlaceEntity(id: e.id)?.slug, "sherbrooke", "l'entité se relit de son identifiant, sans réseau")104 }105106 func testRecentSalesOfAMunicipality() async throws {107 let r = try await SharedAPI.recentSales(place: .init(slug: "quebec", name: "Québec", units: nil), limit: 4)108 XCTAssertFalse(r.items.isEmpty)109 XCTAssertLessThanOrEqual(r.items.count, 4)110 for s in r.items {111 XCTAssertGreaterThan(s.price ?? 0, 1000, "un prix de vente réel")112 XCTAssertFalse(s.street.isEmpty)113 XCTAssertNotNil(SharedFmt.day(iso: s.date))114 }115 }116117 func testRecentSalesProvinceWide() async throws {118 let r = try await SharedAPI.recentSales(place: nil, limit: 3)119 XCTAssertEqual(r.items.count, 3)120 XCTAssertNotNil(r.updatedTo)121 }122123 func testLocalMarket() async throws {124 let m = try await SharedAPI.market(place: .init(slug: "quebec", name: "Québec", units: nil))125 XCTAssertEqual(m.placeName, "Québec")126 XCTAssertGreaterThan(m.sales ?? 0, 100)127 XCTAssertGreaterThan(m.medianPaid ?? 0, 100_000)128 let qc = try await SharedAPI.market(place: nil)129 XCTAssertGreaterThan(qc.medianPaid ?? 0, 100_000)130 XCTAssertTrue(["12 mois", "30 jours"].contains(qc.window))131 }132133 /// La sonde lit ce que la production sert vraiment aujourd'hui, et les deux lectures concordent.134 func testLevelProbeAgreesWithProduction() async throws {135 let (data, resp) = try await URLSession.shared.data(from: SharedAPI.site.appending(path: "api/v3/version"))136 let code = (resp as? HTTPURLResponse)?.statusCode ?? 0137 let level = code == 200 ? ServiceLevel.read(versionBody: data).level : .v2138 let served = await SharedAPI.servesV3()139 XCTAssertEqual(level == .v3, served)140 // l'API 2 répond toujours : c'est elle qui choisit l'adresse de base141 let (v2, _) = try await URLSession.shared.data(from: SharedAPI.site.appending(path: "api/version"))142 XCTAssertNotNil(APIClient.isV2(v2))143 }144}145