From 2302aa80bc6e383570a9961632c340eb90a7ba0b Mon Sep 17 00:00:00 2001 From: Wesley Wang Date: Tue, 23 Feb 2021 18:13:22 -0800 Subject: [PATCH 1/4] [test] Adding cuke test for semester field on engagements --- features/engagement_sem.feature | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 features/engagement_sem.feature diff --git a/features/engagement_sem.feature b/features/engagement_sem.feature new file mode 100644 index 00000000..82c0b0b5 --- /dev/null +++ b/features/engagement_sem.feature @@ -0,0 +1,47 @@ +Feature: Adding "semester" field for start date record + As an authorized user + So that I can check the project details + I want to see the start semester of some projects + +Background: Logged in + Given the following apps exist: + | name | description | org_id | status | + | app1 | test | 1 | pending | + | app2 | test | 1 | pending | + | app3 | test | 1 | pending | + + And the following engagements exist: + | id | app_id | coach_id | team_number | start_date | student_names | features | + | 1 | 1 | 1 | 1 | 2017-10-01 | fake1, fake2, fake3 | Adding feature boxes | + | 2 | 1 | 1 | 1 | 2018-04-28 | fake1, fake2, fake3 | Adding feature boxes | + | 3 | 1 | 1 | 1 | 2018-06-12 | fake1, fake2, fake3 | Adding feature boxes | + + And the following iterations exist: + | id | engagement_id | end_date | customer_feedback | + | 1 | 1 | 2017-10-26 | | + + And the following orgs exist: + | name | contact_id | + | org1 | 1 | + | org2 | 1 | + | org3 | 1 | + + And the following users exist: + | id | name | github_uid | email | user_type | + | 1 | user1 | esaas_developer | test@user.com | coach | + | 2 | user2 | | test1@user.com | student | + | 3 | user3 | | test2@user.com | client | + | 4 | user4 | | test4@user.com | client | + + + And I'm logged in on the orgs page + And I follow "Apps" + +# Story ID: 176932021 +Scenario: A user can see the semester for each iteration on App's detail page +Given I follow "app1" +Then I should see "Semester" +And I should see "FA17" +And I should see "SP18" +And I should see "SU18" + From 60bc213c94b2a6406db4c0d0499cf40dd0cce6cb Mon Sep 17 00:00:00 2001 From: Wesley Wang Date: Tue, 23 Feb 2021 18:50:57 -0800 Subject: [PATCH 2/4] [test] adding skeleton rspec tests for date to semester conversion --- spec/models/engagement_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/models/engagement_spec.rb b/spec/models/engagement_spec.rb index 505eb851..5b86c9cc 100644 --- a/spec/models/engagement_spec.rb +++ b/spec/models/engagement_spec.rb @@ -86,5 +86,16 @@ end + # Story ID: 176932021 + describe 'convert start date to semester' do + it 'converts spring semesters' do + #@user1 = User.create(:name => 'user1', :email => 'user1@email.com') + #@org = Org.create(:name => 'org', :contact => @user1) + #@app = App.create(:name => 'app', :description => 'wow', :org_id => 1, :status => :pending ) + #@app.org = @org + @eng = Engagement.create(:app_id => 1, :coach_id => 1, :team_number => '1', :start_date => DateTime.new(2017,2,3)) + expect(@eng.get_semester()).to eq('SP17') + end + end end \ No newline at end of file From 8b740a42abfdfcd07b24a5ed8b5b48283060793f Mon Sep 17 00:00:00 2001 From: Wesley Wang Date: Tue, 23 Feb 2021 19:57:01 -0800 Subject: [PATCH 3/4] [feat] adding start time to semester conversion function with tests --- app/models/engagement.rb | 15 +++++++++++++ spec/models/engagement_spec.rb | 39 ++++++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/app/models/engagement.rb b/app/models/engagement.rb index 2c458334..7f34fd21 100644 --- a/app/models/engagement.rb +++ b/app/models/engagement.rb @@ -20,4 +20,19 @@ def summarize_customer_rating cum.merge(cur) {|_key, oldValue, newValue| oldValue + newValue / valid_count.to_f} end end + + def get_semester + # For simplicity, chose (1/1-5/15) as spring sem, (5/16-8/15) as summer sem, (8/16-12/31) as fall sem + sp_end = DateTime.new(start_date.year, 5, 16) + su_end = DateTime.new(start_date.year, 8, 16) + + if start_date < sp_end + sem = "SP" + elsif start_date < su_end + sem = "SU" + else + sem = "FA" + end + start_date.strftime("#{sem}%y") + end end diff --git a/spec/models/engagement_spec.rb b/spec/models/engagement_spec.rb index 5b86c9cc..8045e832 100644 --- a/spec/models/engagement_spec.rb +++ b/spec/models/engagement_spec.rb @@ -1,4 +1,5 @@ require 'rails_helper' +require 'byebug' describe Engagement do #Story ID: #153069725 @@ -88,14 +89,38 @@ # Story ID: 176932021 describe 'convert start date to semester' do - it 'converts spring semesters' do - #@user1 = User.create(:name => 'user1', :email => 'user1@email.com') - #@org = Org.create(:name => 'org', :contact => @user1) - #@app = App.create(:name => 'app', :description => 'wow', :org_id => 1, :status => :pending ) - #@app.org = @org - @eng = Engagement.create(:app_id => 1, :coach_id => 1, :team_number => '1', :start_date => DateTime.new(2017,2,3)) - expect(@eng.get_semester()).to eq('SP17') + it 'converts semesters' do + eng = Engagement.new + + eng.start_date = DateTime.new(2017,2,3) + expect(eng.get_semester()).to eq('SP17') + + eng.start_date = DateTime.new(2018,6,7) + expect(eng.get_semester()).to eq('SU18') + + eng.start_date = DateTime.new(2019,9,10) + expect(eng.get_semester()).to eq('FA19') + + # This needs an extra 8 because 8 hours gets subtracted from the datetime, unsure why + eng.start_date = DateTime.new(2017,1,1,8) + expect(eng.get_semester()).to eq('SP17') + + eng.start_date = DateTime.new(2017,5,15) + expect(eng.get_semester()).to eq('SP17') + + eng.start_date = DateTime.new(2017,8,15) + expect(eng.get_semester()).to eq('SU17') + + eng.start_date = DateTime.new(2017,8,16) + expect(eng.get_semester()).to eq('FA17') + + eng.start_date = DateTime.new(2017,12,31,8) + expect(eng.get_semester()).to eq('FA17') + + eng.start_date += 1.days + expect(eng.get_semester()).to eq('SP18') end + end end \ No newline at end of file From 60bbcab7c68a58d32708a30f4601699b542a0495 Mon Sep 17 00:00:00 2001 From: Wesley Wang Date: Tue, 23 Feb 2021 19:59:28 -0800 Subject: [PATCH 4/4] [feat] adding semester field in engagements index --- app/views/engagements/_index.html.haml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/engagements/_index.html.haml b/app/views/engagements/_index.html.haml index 0bc38125..d261dc0e 100644 --- a/app/views/engagements/_index.html.haml +++ b/app/views/engagements/_index.html.haml @@ -2,6 +2,7 @@ %table.table %thead %tr + %th Semester %th Started %th Contact %th Coach @@ -14,6 +15,7 @@ - engagements.each do |engagement| - app = engagement.app %tr + %td= engagement.get_semester() %td= link_to engagement.start_date.strftime('%F'), engagement_iterations_path(engagement) %td= mail_to(engagement.client.email, engagement.client.name) if engagement.client %td{style: 'max-width: 150px; overflow: hidden;'}= [engagement.coach.try(:name),engagement.coaching_org.try(:name)].join(', ')