mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-04 10:00:55 +01:00
Prettier
This commit is contained in:
parent
bded3c1bd6
commit
45da5e3ecb
2 changed files with 32 additions and 19 deletions
|
@ -12,27 +12,38 @@ export const renderCard = async (
|
|||
if (typeof values.choice1_count !== 'undefined') {
|
||||
const poll = {} as APIPoll;
|
||||
|
||||
if (typeof values.end_datetime_utc !== 'undefined') {
|
||||
poll.ends_at = values.end_datetime_utc.string_value || '';
|
||||
poll.time_left_en = calculateTimeLeftString(new Date(values.end_datetime_utc.string_value));
|
||||
}
|
||||
poll.ends_at = values.end_datetime_utc?.string_value || '';
|
||||
poll.time_left_en = calculateTimeLeftString(
|
||||
new Date(values.end_datetime_utc?.string_value || '')
|
||||
);
|
||||
|
||||
const choices: { [label: string]: number } = {
|
||||
[values.choice1_label?.string_value || '']: parseInt(values.choice1_count?.string_value || '0'),
|
||||
[values.choice2_label?.string_value || '']: parseInt(values.choice2_count?.string_value || '0'),
|
||||
[values.choice3_label?.string_value || '']: parseInt(values.choice3_count?.string_value || '0'),
|
||||
[values.choice4_label?.string_value || '']: parseInt(values.choice4_count?.string_value || '0')
|
||||
}
|
||||
[values.choice1_label?.string_value || '']: parseInt(
|
||||
values.choice1_count?.string_value || '0'
|
||||
),
|
||||
[values.choice2_label?.string_value || '']: parseInt(
|
||||
values.choice2_count?.string_value || '0'
|
||||
),
|
||||
[values.choice3_label?.string_value || '']: parseInt(
|
||||
values.choice3_count?.string_value || '0'
|
||||
),
|
||||
[values.choice4_label?.string_value || '']: parseInt(
|
||||
values.choice4_count?.string_value || '0'
|
||||
)
|
||||
};
|
||||
|
||||
poll.total_votes = Object.values(choices).reduce((a, b) => a + b, 0);
|
||||
|
||||
poll.choices = Object.keys(choices).filter(label => label !== '').map(label => {
|
||||
return {
|
||||
label: label,
|
||||
count: choices[label],
|
||||
percentage: (Math.round((choices[label] / poll.total_votes) * 1000) || 0) / 10 || 0
|
||||
};
|
||||
});
|
||||
poll.choices = Object.keys(choices)
|
||||
.filter(label => label !== '')
|
||||
.map(label => {
|
||||
return {
|
||||
label: label,
|
||||
count: choices[label],
|
||||
percentage:
|
||||
(Math.round((choices[label] / poll.total_votes) * 1000) || 0) / 10 || 0
|
||||
};
|
||||
});
|
||||
|
||||
return { poll: poll };
|
||||
} else if (typeof values.player_url !== 'undefined') {
|
||||
|
|
|
@ -273,7 +273,9 @@ test('API fetch poll Tweet', async () => {
|
|||
|
||||
const tweet = response.tweet as APITweet;
|
||||
expect(tweet).toBeTruthy();
|
||||
expect(tweet.url).toEqual('https://twitter.com/dangeredwolf/status/1547441637739184128');
|
||||
expect(tweet.url).toEqual(
|
||||
'https://twitter.com/dangeredwolf/status/1547441637739184128'
|
||||
);
|
||||
expect(tweet.id).toEqual('1547441637739184128');
|
||||
expect(tweet.text).toEqual('Poll with 4 values');
|
||||
expect(tweet.author.screen_name?.toLowerCase()).toEqual('dangeredwolf');
|
||||
|
@ -291,7 +293,7 @@ test('API fetch poll Tweet', async () => {
|
|||
expect(poll.ends_at).toEqual('2022-07-15T04:43:31Z');
|
||||
expect(poll.time_left_en).toEqual('Final results');
|
||||
expect(poll.total_votes).toEqual(194);
|
||||
|
||||
|
||||
const choices = poll.choices as APIPollChoice[];
|
||||
expect(choices[0].label).toEqual('1');
|
||||
expect(choices[0].count).toEqual(14);
|
||||
|
@ -305,4 +307,4 @@ test('API fetch poll Tweet', async () => {
|
|||
expect(choices[3].label).toEqual('4');
|
||||
expect(choices[3].count).toEqual(64);
|
||||
expect(choices[3].percentage).toEqual(33);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue