Skip to content

Commit

Permalink
fix: 1.weather API
Browse files Browse the repository at this point in the history
  • Loading branch information
JuckZ committed Sep 15, 2023
1 parent 9c8611f commit b85d65d
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 110 deletions.
35 changes: 29 additions & 6 deletions src/__test__/weather.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
import { describe, expect, it } from 'vitest';
import { getWeather } from '@/api/weather';
import { beforeAll, describe, expect, it } from 'vitest';
import { WeatherResponseForJournal, getAir, getCurrentLocation, getWeather, getWttrWeather } from '@/api/weather';

let locationId = '';
const apiKey = 'e6d27287b8d54b5da382f19086dac223';
let cityName = '';
beforeAll(async () => {
const currentLocationResponse = await getCurrentLocation(apiKey);
const location = currentLocationResponse?.location[0];
if (location) {
locationId = location.id;
cityName = location.name;
} else {
locationId = '101010100';
}
});
describe('weather', () => {
it('getWeather', async () => {
const weather = await getWeather({ apiKey });
console.log(weather);
it.skip('getWttrWeather', async () => {
const weather = await getWttrWeather('');
expect(weather).not.null;
expect(weather?.daily[0]?.textDay).string;
});

it('getWeather', async () => {
await Promise.all([getWeather({ apiKey }), getAir(locationId, apiKey)]).then(([weather, air]) => {
console.log(weather);
expect(weather).not.null;
expect(weather?.daily[0]?.textDay).string;
if (weather?.daily[0] && air) {
const jouranlResponse = new WeatherResponseForJournal();
const desc = cityName + jouranlResponse.getDesc(weather?.daily[0], air?.now);
console.log(desc);
}
});
});
});
Loading

0 comments on commit b85d65d

Please sign in to comment.