Skip to content

Commit

Permalink
create unarchive event
Browse files Browse the repository at this point in the history
- add factory trait / adapt test
  • Loading branch information
Isalafont committed Nov 30, 2023
1 parent 754b837 commit 79d55f0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion backend/app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Event < ApplicationRecord
revoke
reminder
reminder_before_archive
unarchive

opinion_created
opinion_comment_created
Expand All @@ -24,7 +25,7 @@ class Event < ApplicationRecord
belongs_to :entity, polymorphic: true, optional: true

belongs_to :user, optional: true
validates :user, presence: true, if: proc { |event| %w[reminder reminder_before_archive archive].exclude?(event.name) }
validates :user, presence: true, if: proc { |event| %w[reminder reminder_before_archive archive unarchive].exclude?(event.name) }

validates :name, presence: true, inclusion: {in: VALID_NAMES}

Expand Down
4 changes: 4 additions & 0 deletions backend/spec/factories/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
name { "archive" }
end

trait :unarchive do
name { "unarchive" }
end

trait :opinion_created do
name { "opinion_created" }

Expand Down
4 changes: 4 additions & 0 deletions backend/spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
archive
opinion_created
opinion_comment_created
unarchive
].each do |trait|
expect(build(:event, trait)).to be_valid
end
Expand Down Expand Up @@ -181,6 +182,7 @@
reminder
reminder_before_archive
archive
unarchive
].each do |name|
context "when name is '#{name}'" do
let(:name) { name }
Expand Down Expand Up @@ -239,6 +241,8 @@
%w[
reminder
reminder_before_archive
archive
unarchive
].each do |name|
context "when name '#{name}'" do
let(:name) { name }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
EnrollmentEvent,
} from '../../../../config/event-configuration';
import { processEvent } from '../../../../lib/process-event';
import { createOrUpdateEnrollment } from '../../../../services/enrollments';
import Enrollment from '../../../templates/Enrollment';

export const HeadSection = () => {
const {
Expand All @@ -32,16 +32,18 @@ export const HeadSection = () => {
const handleUnarchiveClick = async () => {
const event = EnrollmentEvent.unarchive;
const eventConfiguration = eventConfigurations[event];
const enrollment = Enrollment;
const updateEnrollment = Function;

try {
const result = await processEvent(
await processEvent(
event,
eventConfiguration,
enrollment,
updateEnrollment
);
} catch (error) {
console.error('Errur lors du désarchivage:', error);
console.error('Erreur lors du désarchivage:', error);
}
};

Expand Down

0 comments on commit 79d55f0

Please sign in to comment.