Created
November 18, 2019 22:01
-
-
Save cdimartino/c87557b8940b3ebefd52a34be5af6ddd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
describe Smart::Representers::QuickTests::QuickTestTemplateRepresenterV1 do | |
let(:user) { create(:user) } | |
let(:study) { create(:study, :quick_test, last_updated_by: user) } | |
let(:quick_test_template) { create(:quick_test_template, :mobile_usability, study_template: study) } | |
let(:quick_test_form_item) { create(:quick_test_form_item, :url, quick_test_template: quick_test_template) } | |
let(:json) { described_class.new(quick_test_template).to_json } | |
around(:each) do |example| | |
freeze_time do | |
example.run | |
end | |
end | |
context "response" do | |
subject { json } | |
it { is_expected.to expose("account_id").as(quick_test_template.account_id) } | |
it { is_expected.to expose("beta").as(quick_test_template.beta) } | |
it { is_expected.to expose("created_at").as(quick_test_template.created_at) } | |
it { is_expected.to expose("creator_id").as(quick_test_template.creator_id) } | |
it { is_expected.to expose("description").as(quick_test_template.description) } | |
it { is_expected.to expose("global").as(quick_test_template.global) } | |
it { is_expected.to expose("help_text").as(quick_test_template.help_text) } | |
it { is_expected.to expose("icon").as(quick_test_template.icon) } | |
it { is_expected.to expose("id").as(quick_test_template.id) } | |
it { is_expected.to expose("key").as(quick_test_template.key) } | |
it { is_expected.to expose("platform_app").as(quick_test_template.platform_app) } | |
it { is_expected.to expose("position").as(quick_test_template.position) } | |
it { is_expected.to expose("quick_test_form_items").as( | |
Smart::Representers::QuickTests::QuickTestFormItemsRepresenterV1.new(quick_test_template.quick_test_form_items)) | |
} | |
it { is_expected.to expose("subtitle").as(quick_test_template.subtitle) } | |
it { is_expected.to expose("test_plan").as(quick_test_template.test_plan) } | |
it { is_expected.to expose("title").as(quick_test_template.title) } | |
it { is_expected.to expose("updated_at").as(quick_test_template.updated_at) } | |
it { is_expected.to expose("workspace_id").as(quick_test_template.workspace_id) } | |
end | |
it_behaves_like "a smart representer" | |
describe "#last_updated_date" do | |
let(:test_plan) { quick_test_template.study_template.test_plan } | |
context "test plan does not have an edit history" do | |
it "returns date from test plan created_at" do | |
expect(json).to expose("last_updated_date").as(test_plan.created_at.to_s(:iso8601)) | |
end | |
end | |
context "test plan has an edit history" do | |
before do | |
test_plan.versions.create( | |
event: "update", | |
whodunnit: {user_id: user.id}.to_s, | |
object: "some object update we don't look at this", | |
object_changes: YAML.dump({ | |
"url" => "https://google.com/" | |
}) | |
) | |
end | |
it "returns date of edit history on test plan" do | |
expect(json).to expose("last_updated_date").as(test_plan.last_edited_by[:created_at].to_s(:iso8601)) | |
end | |
end | |
end | |
describe "#last_updated_user_name" do | |
let(:test_plan) { quick_test_template.study_template.test_plan } | |
context "test plan does not have an edit history" do | |
it "returns name of user who last edited study template" do | |
expect(json).to expose("last_updated_user_name").as(user.full_name) | |
end | |
end | |
context "test plan has an edit history" do | |
before do | |
test_plan.versions.create( | |
event: "update", | |
whodunnit: {user_id: user.id}.to_s, | |
object: "some object update we don't look at this", | |
object_changes: YAML.dump({ | |
"url" => "https://google.com/" | |
}) | |
) | |
end | |
it "returns name of user who last edited test plan" do | |
expect(json).to expose("last_updated_user_name").as(test_plan.last_edited_by[:user].full_name) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment