From fce56deacd3d240714c79e3f5ffc05b467313a3a Mon Sep 17 00:00:00 2001
From: Zacck Osiemo
Date: Tue, 19 Dec 2017 07:43:36 +0200
Subject: [PATCH 1/4] change markup to more friendlier language
---
emails/receipt.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/emails/receipt.html b/emails/receipt.html
index ebbf5c7cf..88d9be963 100644
--- a/emails/receipt.html
+++ b/emails/receipt.html
@@ -45,7 +45,7 @@
From 195a6349d8c0b0884e7db9333d94463d1ff6803c Mon Sep 17 00:00:00 2001
From: Zacck Osiemo
Date: Tue, 19 Dec 2017 07:44:17 +0200
Subject: [PATCH 2/4] add function to get name of user and pass the name into
the email model
---
lib/code_corps/emails/receipt_email.ex | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/lib/code_corps/emails/receipt_email.ex b/lib/code_corps/emails/receipt_email.ex
index 3966190c0..6c5dab270 100644
--- a/lib/code_corps/emails/receipt_email.ex
+++ b/lib/code_corps/emails/receipt_email.ex
@@ -3,9 +3,15 @@ defmodule CodeCorps.Emails.ReceiptEmail do
import Bamboo.PostmarkHelper
alias CodeCorps.Emails.BaseEmail
- alias CodeCorps.{DonationGoal, Project, Repo, StripeConnectCharge, StripeConnectSubscription, WebClient}
+ alias CodeCorps.{DonationGoal, Project, Repo, StripeConnectCharge, StripeConnectSubscription, WebClient, User}
- @spec create(StripeConnectCharge.t, Stripe.Invoice.t) :: Bamboo.Email.t
+ @spec get_name(User.t) :: String.t
+ def get_name(%User{ first_name: nil }), do: "there"
+
+ @spec get_name(User.t) :: String.t
+ def get_name(%User{ first_name: name}), do: name
+
+ @spec create(StripeConnectCharge.t, Stripe.Invoice.t) :: Bamboo.Email.t
def create(%StripeConnectCharge{} = charge, %Stripe.Invoice{} = invoice) do
with %StripeConnectCharge{} = charge <- Repo.preload(charge, :user),
%Project{} = project <- get_project(invoice.subscription),
@@ -55,7 +61,7 @@ defmodule CodeCorps.Emails.ReceiptEmail do
project_title: project.title,
project_url: project |> url(),
subject: project |> build_subject_line(),
- user_first_name: charge.user.first_name
+ name: get_name(charge.user)
}
end
From f07cf779bc9466d5ed107f1bd684ec235b8454ec Mon Sep 17 00:00:00 2001
From: Zacck Osiemo
Date: Tue, 19 Dec 2017 07:44:54 +0200
Subject: [PATCH 3/4] add coverage for nil name checker and update model to use
name
---
test/lib/code_corps/emails/receipt_email_test.exs | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/test/lib/code_corps/emails/receipt_email_test.exs b/test/lib/code_corps/emails/receipt_email_test.exs
index fc744e8b3..328c9de18 100644
--- a/test/lib/code_corps/emails/receipt_email_test.exs
+++ b/test/lib/code_corps/emails/receipt_email_test.exs
@@ -4,6 +4,12 @@ defmodule CodeCorps.Emails.ReceiptEmailTest do
alias CodeCorps.Emails.ReceiptEmail
+
+ test "get name returns there on nil name" do
+ user = %CodeCorps.User{}
+ assert ReceiptEmail.get_name(user) == "there"
+ end
+
test "receipt email works" do
invoice_fixture = CodeCorps.StripeTesting.Helpers.load_fixture("invoice")
@@ -50,7 +56,7 @@ defmodule CodeCorps.Emails.ReceiptEmailTest do
project_url: "http://localhost:4200/#{project.organization.slug}/#{project.slug}",
project_current_donation_goal_description: "Test goal",
subject: "Your monthly donation to Code Corps",
- user_first_name: "Jimmy"
+ name: "Jimmy"
}
assert high_five_image_url
end
From bb8f624a2848eebab0e18edf61f6cf4ae542f96c Mon Sep 17 00:00:00 2001
From: Zacck Osiemo
Date: Thu, 15 Feb 2018 17:12:30 +0200
Subject: [PATCH 4/4] Add test to check that reopened conversations get a
converstationpart with `part_type: "reopened"`
Add test to for conversation part when updated with a status of reopened
Add tests to check for a conversation_part when a conversation is updated with a status of closed
correct erronous field
add function clauses to handle adding closed and reopned conversation_parts
add reopened flag to possible statuses
add time information to body of closed and reopened event
---
lib/code_corps/messages/messages.ex | 21 +++++++++++++
lib/code_corps/model/conversation.ex | 2 +-
.../code_corps/emails/receipt_email_test.exs | 1 -
.../lib/code_corps/messages/messages_test.exs | 31 +++++++++++++++++++
4 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/lib/code_corps/messages/messages.ex b/lib/code_corps/messages/messages.ex
index b7b87a835..47bf736c2 100644
--- a/lib/code_corps/messages/messages.ex
+++ b/lib/code_corps/messages/messages.ex
@@ -12,6 +12,9 @@ defmodule CodeCorps.Messages do
Repo
}
alias Ecto.{Changeset, Queryable}
+
+ @reopened "reopened"
+ @closed "closed"
@doc ~S"""
Lists pre-scoped `CodeCorps.Message` records filtered by parameters.
@@ -52,9 +55,27 @@ defmodule CodeCorps.Messages do
Conversation |> Repo.get(id)
end
+ @doc ~S"""
+ Updates a `CodeCorps.Conversation` record
+ """
+ def update_conversation(conversation, %{status: @reopened} = params) do
+ {:ok, now} = Timex.format(Timex.now, "{ISO:Extended}")
+ add_part(%{"conversation_id" => conversation.id, "body" => "Reopened on " <> now , "author_id"
+ => conversation.user_id, "part_type" => "reopened"})
+ conversation |> Conversation.update_changeset(params) |> Repo.update
+ end
+
+ def update_conversation(conversation, %{status: @closed} = params) do
+ {:ok, now} = Timex.format(Timex.now, "{ISO:Extended}")
+ add_part(%{"conversation_id" => conversation.id, "body" => "Closed on " <> now, "author_id"
+ => conversation.user_id, "part_type" => "closed"})
+ conversation |> Conversation.update_changeset(params) |> Repo.update
+ end
+
def update_conversation(conversation, params) do
conversation |> Conversation.update_changeset(params) |> Repo.update
end
+
@doc ~S"""
Gets a `CodeCorps.ConversationPart` record
diff --git a/lib/code_corps/model/conversation.ex b/lib/code_corps/model/conversation.ex
index a5891cfc4..a38ce43ee 100644
--- a/lib/code_corps/model/conversation.ex
+++ b/lib/code_corps/model/conversation.ex
@@ -34,6 +34,6 @@ defmodule CodeCorps.Conversation do
end
defp statuses do
- ~w{ open closed }
+ ~w{ open closed reopened }
end
end
diff --git a/test/lib/code_corps/emails/receipt_email_test.exs b/test/lib/code_corps/emails/receipt_email_test.exs
index 11863904e..b530ee0ad 100644
--- a/test/lib/code_corps/emails/receipt_email_test.exs
+++ b/test/lib/code_corps/emails/receipt_email_test.exs
@@ -57,7 +57,6 @@ defmodule CodeCorps.Emails.ReceiptEmailTest do
project_url: "http://localhost:4200/#{project.organization.slug}/#{project.slug}",
project_current_donation_goal_description: "Test goal",
subject: "Your monthly donation to Code Corps",
- name: "Jimmy"
}
assert high_five_image_url
end
diff --git a/test/lib/code_corps/messages/messages_test.exs b/test/lib/code_corps/messages/messages_test.exs
index 0fc7b864b..a8978e23c 100644
--- a/test/lib/code_corps/messages/messages_test.exs
+++ b/test/lib/code_corps/messages/messages_test.exs
@@ -242,6 +242,37 @@ defmodule CodeCorps.MessagesTest do
assert result.id == conversation.id
end
end
+
+ describe "update_conversation/2" do
+
+ test "creates a conversation_part of part_type reopened when a conversation is reopened" do
+ conversation = insert(:conversation)
+
+ assert Repo.aggregate(ConversationPart, :count, :id) == 0
+ conversation = Messages.get_conversation(conversation.id)
+ {_ok, _updated} = Messages.update_conversation(conversation,%{status: "reopened"})
+
+ assert Repo.aggregate(ConversationPart, :count, :id) == 1
+
+ conversation_part = Repo.get_by(ConversationPart, part_type: "reopened")
+ assert conversation_part.author_id == conversation.user_id
+ assert conversation_part.conversation_id == conversation.id
+ end
+
+ test "creates a conversation_part of part_type closed when a conversation is closed" do
+ conversation = insert(:conversation)
+
+ assert Repo.aggregate(ConversationPart, :count, :id) == 0
+ conversation = Messages.get_conversation(conversation.id)
+ {_ok, _updated} = Messages.update_conversation(conversation,%{status: "closed"})
+
+ assert Repo.aggregate(ConversationPart, :count, :id) == 1
+
+ conversation_part = Repo.get_by(ConversationPart, part_type: "closed")
+ assert conversation_part.author_id == conversation.user_id
+ assert conversation_part.conversation_id == conversation.id
+ end
+ end
describe "get_part/1" do
test "gets a single part" do
|