diff --git a/app/finders/conversation_finder.rb b/app/finders/conversation_finder.rb index 0cc5e52d8..f3c85be7a 100644 --- a/app/finders/conversation_finder.rb +++ b/app/finders/conversation_finder.rb @@ -169,6 +169,12 @@ class ConversationFinder ) sort_by, sort_order = SORT_OPTIONS[params[:sort_by]] || SORT_OPTIONS['last_activity_at_desc'] - @conversations.send(sort_by, sort_order).page(current_page).per(ENV.fetch('CONVERSATION_RESULTS_PER_PAGE', '25').to_i) + @conversations = @conversations.send(sort_by, sort_order) + + if params[:updated_within].present? + @conversations.where('conversations.updated_at > ?', Time.zone.now - params[:updated_within].to_i.seconds) + else + @conversations.page(current_page).per(ENV.fetch('CONVERSATION_RESULTS_PER_PAGE', '25').to_i) + end end end diff --git a/app/javascript/dashboard/api/agents.js b/app/javascript/dashboard/api/agents.js index 7cc5e6d0c..cfc6b36ff 100644 --- a/app/javascript/dashboard/api/agents.js +++ b/app/javascript/dashboard/api/agents.js @@ -1,9 +1,17 @@ +/* global axios */ + import ApiClient from './ApiClient'; class Agents extends ApiClient { constructor() { super('agents', { accountScoped: true }); } + + bulkInvite({ emails }) { + return axios.post(`${this.url}/bulk_create`, { + emails, + }); + } } export default new Agents(); diff --git a/app/javascript/dashboard/api/specs/agents.spec.js b/app/javascript/dashboard/api/specs/agents.spec.js index 7cf1bdd0e..20dd36688 100644 --- a/app/javascript/dashboard/api/specs/agents.spec.js +++ b/app/javascript/dashboard/api/specs/agents.spec.js @@ -10,4 +10,29 @@ describe('#AgentAPI', () => { expect(agents).toHaveProperty('update'); expect(agents).toHaveProperty('delete'); }); + + describe('API calls', () => { + const originalAxios = window.axios; + const axiosMock = { + post: jest.fn(() => Promise.resolve()), + }; + + beforeEach(() => { + window.axios = axiosMock; + }); + + afterEach(() => { + window.axios = originalAxios; + }); + + it('#bulkInvite', () => { + agents.bulkInvite({ emails: ['hello@hi.com'] }); + expect(axiosMock.post).toHaveBeenCalledWith( + '/api/v1/agents/bulk_create', + { + emails: ['hello@hi.com'], + } + ); + }); + }); }); diff --git a/app/models/notification.rb b/app/models/notification.rb index e0b31b457..f8c6e3d5b 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -4,6 +4,7 @@ # # id :bigint not null, primary key # last_activity_at :datetime +# meta :jsonb # notification_type :integer not null # primary_actor_type :string not null # read_at :datetime diff --git a/db/migrate/20240215065844_add_meta_to_notifications.rb b/db/migrate/20240215065844_add_meta_to_notifications.rb new file mode 100644 index 000000000..e0f93f276 --- /dev/null +++ b/db/migrate/20240215065844_add_meta_to_notifications.rb @@ -0,0 +1,5 @@ +class AddMetaToNotifications < ActiveRecord::Migration[7.0] + def change + add_column :notifications, :meta, :jsonb, default: {} + end +end diff --git a/db/schema.rb b/db/schema.rb index 7d2372554..138ea6835 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_02_07_103014) do +ActiveRecord::Schema[7.0].define(version: 2024_02_15_065844) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "pg_trgm" @@ -750,6 +750,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_02_07_103014) do t.datetime "updated_at", null: false t.datetime "snoozed_until" t.datetime "last_activity_at", default: -> { "CURRENT_TIMESTAMP" } + t.jsonb "meta", default: {} t.index ["account_id"], name: "index_notifications_on_account_id" t.index ["last_activity_at"], name: "index_notifications_on_last_activity_at" t.index ["primary_actor_type", "primary_actor_id"], name: "uniq_primary_actor_per_account_notifications" diff --git a/spec/finders/conversation_finder_spec.rb b/spec/finders/conversation_finder_spec.rb index 2ce5b6bf9..4d6e9ed40 100644 --- a/spec/finders/conversation_finder_spec.rb +++ b/spec/finders/conversation_finder_spec.rb @@ -146,6 +146,30 @@ describe ConversationFinder do end end + context 'with updated_within' do + let(:params) { { updated_within: 20, assignee_type: 'unassigned', sort_by: 'created_at_asc' } } + + it 'filters based on params, sort order but returns all conversations without pagination with in time range' do + # value of updated_within is in seconds + # write spec based on that + conversations = create_list(:conversation, 50, account: account, + inbox: inbox, assignee: nil, + updated_at: Time.now.utc - 30.seconds, + created_at: Time.now.utc - 30.seconds) + # update updated_at of 27 conversations to be with in 20 seconds + conversations[0..27].each do |conversation| + conversation.update(updated_at: Time.now.utc - 10.seconds) + end + result = conversation_finder.perform + # pagination is not applied + # filters are applied + # modified conversations + 1 conversation created during set up + expect(result[:conversations].length).to be 29 + # ensure that the conversations are sorted by created_at + expect(result[:conversations].first.created_at).to be < result[:conversations].last.created_at + end + end + context 'with pagination' do let(:params) { { status: 'open', assignee_type: 'me', page: 1 } }