mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-04 10:00:55 +01:00
✨ Added birthday support and fixed test
This commit is contained in:
parent
959726be46
commit
d7ce35c413
3 changed files with 39 additions and 43 deletions
|
@ -20,7 +20,7 @@ const populateUserProperties = async (
|
|||
const user = response.data.user.result;
|
||||
/* Populating a lot of the basics */
|
||||
apiUser.url = `${Constants.TWITTER_ROOT}/${user.legacy.screen_name}`;
|
||||
apiUser.id = user.id;
|
||||
apiUser.id = user.rest_id;
|
||||
apiUser.followers = user.legacy.followers_count;
|
||||
apiUser.following = user.legacy.friends_count;
|
||||
apiUser.likes = user.legacy.favourites_count;
|
||||
|
@ -31,6 +31,14 @@ const populateUserProperties = async (
|
|||
apiUser.location = user.legacy.location;
|
||||
apiUser.verified = user.legacy.verified;
|
||||
apiUser.avatar_url = user.legacy.profile_image_url_https;
|
||||
apiUser.joined = user.legacy.created_at;
|
||||
if (user.legacy_extended_profile?.birthdate) {
|
||||
const { birthdate } = user.legacy_extended_profile;
|
||||
apiUser.birthday = {};
|
||||
if (typeof birthdate.day === 'number') apiUser.birthday.day = birthdate.day;
|
||||
if (typeof birthdate.month === 'number') apiUser.birthday.month = birthdate.month;
|
||||
if (typeof birthdate.year === 'number') apiUser.birthday.year = birthdate.year;
|
||||
}
|
||||
|
||||
return apiUser;
|
||||
};
|
||||
|
@ -77,13 +85,13 @@ export const userAPI = async (
|
|||
|
||||
/* Creating the response objects */
|
||||
const response: UserAPIResponse = { code: 200, message: 'OK' } as UserAPIResponse;
|
||||
const apiTweet: APIUser = (await populateUserProperties(
|
||||
const apiUser: APIUser = (await populateUserProperties(
|
||||
userResponse,
|
||||
language
|
||||
)) as APIUser;
|
||||
|
||||
/* Finally, staple the User to the response and return it */
|
||||
response.user = apiTweet;
|
||||
response.user = apiUser;
|
||||
|
||||
writeDataPoint(event, language, 'OK', flags);
|
||||
|
||||
|
|
5
src/types/types.d.ts
vendored
5
src/types/types.d.ts
vendored
|
@ -165,4 +165,9 @@ interface APIUser {
|
|||
tweets: number;
|
||||
likes: number;
|
||||
joined: string;
|
||||
birthday: {
|
||||
day?: number;
|
||||
month?: number;
|
||||
year?: number
|
||||
}
|
||||
}
|
|
@ -71,7 +71,7 @@ test('API fetch basic Tweet', async () => {
|
|||
})
|
||||
);
|
||||
expect(result.status).toEqual(200);
|
||||
const response = (await result.json()) as APIResponse;
|
||||
const response = (await result.json()) as TweetAPIResponse;
|
||||
expect(response).toBeTruthy();
|
||||
expect(response.code).toEqual(200);
|
||||
expect(response.message).toEqual('OK');
|
||||
|
@ -104,7 +104,7 @@ test('API fetch video Tweet', async () => {
|
|||
})
|
||||
);
|
||||
expect(result.status).toEqual(200);
|
||||
const response = (await result.json()) as APIResponse;
|
||||
const response = (await result.json()) as TweetAPIResponse;
|
||||
expect(response).toBeTruthy();
|
||||
expect(response.code).toEqual(200);
|
||||
expect(response.message).toEqual('OK');
|
||||
|
@ -150,7 +150,7 @@ test('API fetch multi-photo Tweet', async () => {
|
|||
})
|
||||
);
|
||||
expect(result.status).toEqual(200);
|
||||
const response = (await result.json()) as APIResponse;
|
||||
const response = (await result.json()) as TweetAPIResponse;
|
||||
expect(response).toBeTruthy();
|
||||
expect(response.code).toEqual(200);
|
||||
expect(response.message).toEqual('OK');
|
||||
|
@ -195,7 +195,7 @@ test('API fetch multi-photo Tweet', async () => {
|
|||
// })
|
||||
// );
|
||||
// expect(result.status).toEqual(200);
|
||||
// const response = (await result.json()) as APIResponse;
|
||||
// const response = (await result.json()) as TweetAPIResponse;
|
||||
// expect(response).toBeTruthy();
|
||||
// expect(response.code).toEqual(200);
|
||||
// expect(response.message).toEqual('OK');
|
||||
|
@ -272,7 +272,7 @@ test('API fetch poll Tweet', async () => {
|
|||
})
|
||||
);
|
||||
expect(result.status).toEqual(200);
|
||||
const response = (await result.json()) as APIResponse;
|
||||
const response = (await result.json()) as TweetAPIResponse;
|
||||
expect(response).toBeTruthy();
|
||||
expect(response.code).toEqual(200);
|
||||
expect(response.message).toEqual('OK');
|
||||
|
@ -321,43 +321,26 @@ test('API fetch user', async () => {
|
|||
})
|
||||
);
|
||||
expect(result.status).toEqual(200);
|
||||
const response = (await result.json()) as APIResponse;
|
||||
const response = (await result.json()) as UserAPIResponse;
|
||||
expect(response).toBeTruthy();
|
||||
expect(response.code).toEqual(200);
|
||||
expect(response.message).toEqual('OK');
|
||||
|
||||
const tweet = response.tweet as APITweet;
|
||||
expect(tweet).toBeTruthy();
|
||||
expect(tweet.url).toEqual('https://twitter.com/Twitter/status/1055475950543167488');
|
||||
expect(tweet.id).toEqual('1055475950543167488');
|
||||
expect(tweet.text).toEqual('A poll:');
|
||||
expect(tweet.author.screen_name?.toLowerCase()).toEqual('twitter');
|
||||
expect(tweet.author.name).toBeTruthy();
|
||||
expect(tweet.author.avatar_url).toBeTruthy();
|
||||
expect(tweet.author.banner_url).toBeTruthy();
|
||||
expect(tweet.author.avatar_color).toBeTruthy();
|
||||
expect(tweet.twitter_card).toEqual('tweet');
|
||||
expect(tweet.created_at).toEqual('Thu Oct 25 15:07:31 +0000 2018');
|
||||
expect(tweet.created_timestamp).toEqual(1540480051);
|
||||
expect(tweet.lang).toEqual('en');
|
||||
expect(tweet.replying_to).toBeNull();
|
||||
expect(tweet.poll).toBeTruthy();
|
||||
const poll = tweet.poll as APIPoll;
|
||||
expect(poll.ends_at).toEqual('2018-10-26T03:07:30Z');
|
||||
expect(poll.time_left_en).toEqual('Final results');
|
||||
expect(poll.total_votes).toEqual(54703);
|
||||
|
||||
const choices = poll.choices as APIPollChoice[];
|
||||
expect(choices[0].label).toEqual('Yesssss');
|
||||
expect(choices[0].count).toEqual(14773);
|
||||
expect(choices[0].percentage).toEqual(27);
|
||||
expect(choices[1].label).toEqual('No');
|
||||
expect(choices[1].count).toEqual(3618);
|
||||
expect(choices[1].percentage).toEqual(6.6);
|
||||
expect(choices[2].label).toEqual('Maybe?');
|
||||
expect(choices[2].count).toEqual(4606);
|
||||
expect(choices[2].percentage).toEqual(8.4);
|
||||
expect(choices[3].label).toEqual('Just show me the results');
|
||||
expect(choices[3].count).toEqual(31706);
|
||||
expect(choices[3].percentage).toEqual(58);
|
||||
const user = response.user as APIUser;
|
||||
expect(user).toBeTruthy();
|
||||
expect(user.url).toEqual('https://twitter.com/wazbat');
|
||||
expect(user.id).toEqual('157658332');
|
||||
expect(user.name).toEqual('Wazbat');
|
||||
expect(user.screen_name).toEqual('wazbat');
|
||||
expect(user.location).toEqual('Behind you');
|
||||
expect(user.followers).toBeGreaterThanOrEqual(1_000);
|
||||
expect(user.followers).toBeLessThanOrEqual(100_000);
|
||||
expect(user.following).toBeGreaterThanOrEqual(10);
|
||||
expect(user.following).toBeLessThanOrEqual(1_000);
|
||||
expect(user.likes).toBeGreaterThanOrEqual(10_000);
|
||||
expect(user.verified).toEqual(false);
|
||||
expect(user.joined).toEqual('Sun Jun 20 13:29:36 +0000 2010');
|
||||
expect(user.birthday.day).toEqual(14);
|
||||
expect(user.birthday.month).toEqual(7);
|
||||
expect(user.birthday.year).toBeUndefined();
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue