mirror of
https://github.com/kennethnym/aris.git
synced 2026-02-02 13:11:17 +00:00
Refactor WeatherKit client to injectable interface
- Add WeatherKitClient interface and DefaultWeatherKitClient class - WeatherKitDataSource accepts either client or credentials - Simplify tests by injecting mock client directly - Update fixture generation script to use new client class Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { fetchWeather } from "../src/weatherkit"
|
||||
import { DefaultWeatherKitClient } from "../src/weatherkit"
|
||||
|
||||
function loadEnv(): Record<string, string> {
|
||||
const content = require("fs").readFileSync(".env", "utf-8")
|
||||
@@ -26,12 +26,12 @@ function loadEnv(): Record<string, string> {
|
||||
|
||||
const env = loadEnv()
|
||||
|
||||
const credentials = {
|
||||
const client = new DefaultWeatherKitClient({
|
||||
privateKey: env.WEATHERKIT_PRIVATE_KEY!,
|
||||
keyId: env.WEATHERKIT_KEY_ID!,
|
||||
teamId: env.WEATHERKIT_TEAM_ID!,
|
||||
serviceId: env.WEATHERKIT_SERVICE_ID!,
|
||||
}
|
||||
})
|
||||
|
||||
const locations = {
|
||||
sanFrancisco: { lat: 37.7749, lng: -122.4194 },
|
||||
@@ -40,10 +40,10 @@ const locations = {
|
||||
async function main() {
|
||||
console.log("Fetching weather data for San Francisco...")
|
||||
|
||||
const response = await fetchWeather(
|
||||
{ credentials },
|
||||
{ lat: locations.sanFrancisco.lat, lng: locations.sanFrancisco.lng },
|
||||
)
|
||||
const response = await client.fetch({
|
||||
lat: locations.sanFrancisco.lat,
|
||||
lng: locations.sanFrancisco.lng,
|
||||
})
|
||||
|
||||
const fixture = {
|
||||
generatedAt: new Date().toISOString(),
|
||||
|
||||
Reference in New Issue
Block a user