|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# == Schema Information |
| 4 | +# |
| 5 | +# Table name: user_extension_configs |
| 6 | +# |
| 7 | +# id :bigint not null, primary key |
| 8 | +# advanced_editing :boolean default(FALSE), not null |
| 9 | +# default_color_lab :string default("#f6bf26"), not null |
| 10 | +# default_color_lecture :string default("#039be5"), not null |
| 11 | +# enrolled_terms :jsonb not null |
| 12 | +# military_time :boolean default(FALSE), not null |
| 13 | +# show_historic_terms :boolean default(TRUE), not null |
| 14 | +# sync_university_events :boolean default(FALSE), not null |
| 15 | +# university_event_categories :jsonb |
| 16 | +# created_at :datetime not null |
| 17 | +# updated_at :datetime not null |
| 18 | +# user_id :bigint not null |
| 19 | +# |
| 20 | +require "rails_helper" |
| 21 | + |
| 22 | +RSpec.describe UserExtensionConfig, type: :model do |
| 23 | + let(:user) do |
| 24 | + User.create!( |
| 25 | + email: "config-spec@example.com", |
| 26 | + password: "password123", |
| 27 | + password_confirmation: "password123" |
| 28 | + ) |
| 29 | + end |
| 30 | + |
| 31 | + # The user model creates a UserExtensionConfig on create; reuse it. |
| 32 | + let(:config) { user.user_extension_config } |
| 33 | + |
| 34 | + before do |
| 35 | + allow(GoogleCalendarSyncJob).to receive(:perform_later) |
| 36 | + end |
| 37 | + |
| 38 | + describe "toggling sync_university_events" do |
| 39 | + before do |
| 40 | + config.update!( |
| 41 | + sync_university_events: true, |
| 42 | + university_event_categories: %w[campus_event deadline] |
| 43 | + ) |
| 44 | + end |
| 45 | + |
| 46 | + it "preserves selected event types when sync is disabled" do |
| 47 | + config.update!(sync_university_events: false) |
| 48 | + |
| 49 | + expect(config.reload.university_event_categories).to eq(%w[campus_event deadline]) |
| 50 | + end |
| 51 | + |
| 52 | + it "retains selected event types after disabling and re-enabling sync" do |
| 53 | + config.update!(sync_university_events: false) |
| 54 | + config.update!(sync_university_events: true) |
| 55 | + |
| 56 | + expect(config.reload.university_event_categories).to eq(%w[campus_event deadline]) |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + describe "sync_calendar_if_settings_changed" do |
| 61 | + it "enqueues a forced calendar sync when sync_university_events changes" do |
| 62 | + config.update!(sync_university_events: true) |
| 63 | + |
| 64 | + expect(GoogleCalendarSyncJob).to have_received(:perform_later).with(user, force: true) |
| 65 | + end |
| 66 | + |
| 67 | + it "enqueues a forced calendar sync when university_event_categories changes" do |
| 68 | + config.update!(sync_university_events: true) |
| 69 | + config.update!(university_event_categories: %w[finals]) |
| 70 | + |
| 71 | + expect(GoogleCalendarSyncJob).to have_received(:perform_later).with(user, force: true).twice |
| 72 | + end |
| 73 | + end |
| 74 | +end |
0 commit comments