mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 03:57:52 +00:00
chore: fix flaky spec (#7686)
- fix flaky reporting specs - fix flaky export spec
This commit is contained in:
@@ -9,7 +9,8 @@ describe V2::ReportBuilder do
|
|||||||
# Update this spec to use travel_to
|
# Update this spec to use travel_to
|
||||||
# This spec breaks in certain timezone
|
# This spec breaks in certain timezone
|
||||||
describe '#timeseries' do
|
describe '#timeseries' do
|
||||||
before_all do
|
before do
|
||||||
|
travel_to(Time.zone.today) do
|
||||||
user = create(:user, account: account)
|
user = create(:user, account: account)
|
||||||
inbox = create(:inbox, account: account)
|
inbox = create(:inbox, account: account)
|
||||||
create(:inbox_member, user: user, inbox: inbox)
|
create(:inbox_member, user: user, inbox: inbox)
|
||||||
@@ -52,6 +53,7 @@ describe V2::ReportBuilder do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when report type is account' do
|
context 'when report type is account' do
|
||||||
it 'return conversations count' do
|
it 'return conversations count' do
|
||||||
@@ -100,6 +102,7 @@ describe V2::ReportBuilder do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'return resolutions count' do
|
it 'return resolutions count' do
|
||||||
|
travel_to(Time.zone.today) do
|
||||||
params = {
|
params = {
|
||||||
metric: 'resolutions_count',
|
metric: 'resolutions_count',
|
||||||
type: :account,
|
type: :account,
|
||||||
@@ -123,6 +126,7 @@ describe V2::ReportBuilder do
|
|||||||
expect(metrics[Time.zone.today]).to be 4
|
expect(metrics[Time.zone.today]).to be 4
|
||||||
expect(metrics[Time.zone.today - 2.days]).to be 0
|
expect(metrics[Time.zone.today - 2.days]).to be 0
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns average first response time' do
|
it 'returns average first response time' do
|
||||||
params = {
|
params = {
|
||||||
@@ -218,6 +222,7 @@ describe V2::ReportBuilder do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'return resolutions count' do
|
it 'return resolutions count' do
|
||||||
|
travel_to(Time.zone.today) do
|
||||||
params = {
|
params = {
|
||||||
metric: 'resolutions_count',
|
metric: 'resolutions_count',
|
||||||
type: :label,
|
type: :label,
|
||||||
@@ -243,6 +248,7 @@ describe V2::ReportBuilder do
|
|||||||
expect(metrics[Time.zone.today]).to be 4
|
expect(metrics[Time.zone.today]).to be 4
|
||||||
expect(metrics[Time.zone.today - 2.days]).to be 0
|
expect(metrics[Time.zone.today - 2.days]).to be 0
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns average first response time' do
|
it 'returns average first response time' do
|
||||||
label_2.reporting_events.update(value: 1.5)
|
label_2.reporting_events.update(value: 1.5)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ RSpec.describe 'Reports API', type: :request do
|
|||||||
|
|
||||||
before do
|
before do
|
||||||
create_list(:conversation, 10, account: account, inbox: inbox,
|
create_list(:conversation, 10, account: account, inbox: inbox,
|
||||||
assignee: user, created_at: Time.zone.today)
|
assignee: user, created_at: Time.current.in_time_zone(default_timezone).to_date)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET /api/v2/accounts/:account_id/reports/account' do
|
describe 'GET /api/v2/accounts/:account_id/reports/account' do
|
||||||
|
|||||||
@@ -37,15 +37,13 @@ RSpec.describe Account::ContactsExportJob do
|
|||||||
described_class.perform_now(account.id, [])
|
described_class.perform_now(account.id, [])
|
||||||
|
|
||||||
csv_data = CSV.parse(account.contacts_export.download, headers: true)
|
csv_data = CSV.parse(account.contacts_export.download, headers: true)
|
||||||
first_row = csv_data[0]
|
emails = csv_data.pluck('email')
|
||||||
last_row = csv_data[csv_data.length - 1]
|
phone_numbers = csv_data.pluck('phone_number')
|
||||||
first_contact = account.contacts.find_by(email: 'test1@text.example')
|
|
||||||
last_contact = account.contacts.find_by(email: 'test2@text.example')
|
|
||||||
|
|
||||||
expect(csv_data.length).to eq(account.contacts.count)
|
expect(csv_data.length).to eq(account.contacts.count)
|
||||||
|
|
||||||
expect([first_row['email'], last_row['email']]).to contain_exactly(first_contact.email, last_contact.email)
|
expect(emails).to include('test1@text.example', 'test2@text.example')
|
||||||
expect([first_row['phone_number'], last_row['phone_number']]).to contain_exactly(first_contact.phone_number, last_contact.phone_number)
|
expect(phone_numbers).to include('+910808080818', '+910808080808')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user