-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfor_education_spec.rb
More file actions
114 lines (95 loc) · 4.01 KB
/
for_education_spec.rb
File metadata and controls
114 lines (95 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# frozen_string_literal: true
require 'rails_helper'
require 'rake'
require 'climate_control'
require 'securerandom'
RSpec.describe 'for_education', type: :task do
before do
# Ensure the school id is unique, to avoid conflicts
stub_const('SeedsHelper::TEST_SCHOOL', school_id)
end
let(:creator_id) { 'f83ba872-b16e-46e1-9f7d-df89d267550d' }
let(:teacher_id) { 'ccc9b8fd-f357-4238-983d-6f87b99bdbb2' }
let(:student_1) { 'e52de409-9210-4e94-b08c-dd11439e07d9' } # jane.smith from SeedsHelper
let(:student_2) { '0d488bec-b10d-46d3-b6f3-4cddf5d90c71' } # john.smith from SeedsHelper
let(:school_id) { SecureRandom.uuid }
describe ':destroy_seed_data' do
let(:task) { Rake::Task['for_education:destroy_seed_data'] }
let(:school) { create(:school, creator_id:, id: school_id) }
before do
create(:role, user_id: creator_id, school:)
create(:student_role, user_id: student_1, school:)
create(:teacher_role, user_id: creator_id, school:)
school_class = create(:school_class, school_id: school.id, teacher_ids: [creator_id])
create(:class_student, student_id: student_1, school_class_id: school_class.id)
create(:lesson, school_id: school.id, user_id: creator_id)
end
it 'destroys all seed data' do
ClimateControl.modify SEEDING_CREATOR_ID: creator_id, SEEDING_TEACHER_ID: teacher_id do
task.invoke
end
expect(Role.where(user_id: [creator_id, teacher_id, student_1, student_2])).not_to exist
expect(School.where(creator_id:)).not_to exist
expect(ClassStudent.where(student_id: student_1)).not_to exist
expect(SchoolClass.where(school_id: school.id)).not_to exist
expect(ClassTeacher.where(teacher_id: creator_id)).not_to exist
expect(Lesson.where(school_id: school.id)).not_to exist
expect(Project.where(school_id: school.id)).not_to exist
end
end
describe ':seed_an_unverified_school' do
let(:task) { Rake::Task['for_education:seed_an_unverified_school'] }
it 'creates an unverified school' do
ClimateControl.modify SEEDING_CREATOR_ID: creator_id do
task.invoke
end
expect(School.find_by(creator_id:).verified_at).to be_nil
end
end
describe ':seed_a_verified_school' do
let(:task) { Rake::Task['for_education:seed_a_verified_school'] }
it 'creates a verified school' do
ClimateControl.modify SEEDING_CREATOR_ID: creator_id do
task.invoke
end
expect(School.find_by(creator_id:).verified_at).to be_truthy
end
end
describe ':seed_a_school_with_lessons_and_students' do
let(:task) { Rake::Task['for_education:seed_a_school_with_lessons_and_students'] }
let(:school) { School.find_by(creator_id:) }
before do
ClimateControl.modify SEEDING_CREATOR_ID: creator_id, SEEDING_TEACHER_ID: teacher_id do
task.invoke
end
end
it 'creates a verified school' do
expect(school.verified_at).to be_truthy
end
it 'creates a school class' do
expect(SchoolClass.where(school_id: school.id)).to exist
end
it 'adds two lessons to the school' do
lessons = Lesson.where(school_id: school.id)
expect(lessons.count).to eq(2)
end
it 'adds two projects' do
lesson = Lesson.where(school_id: school.id)
expect(Project.where(lesson_id: lesson.pluck(:id)).length).to eq(2)
end
it 'assigns a teacher' do
expect(Role.teacher.where(user_id: teacher_id, school_id: school.id)).to exist
end
it 'creates a class teacher association for the creator' do
expect(ClassTeacher.where(teacher_id: creator_id).length).to eq(1)
end
it 'assigns students' do
school_id = school.id
school_class_id = SchoolClass.find_by(school_id:).id
expect(Role.student.where(user_id: student_1, school_id:)).to exist
expect(ClassStudent.where(student_id: student_1, school_class_id:)).to exist
expect(Role.student.where(user_id: student_2, school_id:)).to exist
expect(ClassStudent.where(student_id: student_2, school_class_id:)).to exist
end
end
end