Skip to content

Commit

Permalink
all tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshull committed Apr 30, 2024
1 parent ff5345e commit b26c837
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 36 deletions.
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ config :dotcom, :cache, Dotcom.Cache.TestCache

config :dotcom, :httpoison, HTTPoison.Mock

config :dotcom, :cms_api_module, CMS.Api.Mock
config :dotcom, :cms_api_module, CMS.Api.Static
config :dotcom, :mbta_api_module, MBTA.Api.Mock

config :dotcom, :redis, Dotcom.Redis.Mock
Expand Down
2 changes: 1 addition & 1 deletion lib/cms/api/static.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule CMS.API.Static do
defmodule CMS.Api.Static do
@moduledoc """
This module provides static responses for the CMS API.
Expand Down
2 changes: 1 addition & 1 deletion lib/dotcom_web/controllers/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ defmodule DotcomWeb.ControllerHelpers do
"""
@spec forward_static_file(Conn.t(), String.t()) :: Conn.t()
def forward_static_file(conn, url) do
case client() |> @req.get(url) do
case client() |> @req.get(url: url) do
{:ok, %{status: 200, body: body, headers: headers}} ->
conn
|> add_headers_if_valid(headers)
Expand Down
4 changes: 2 additions & 2 deletions test/cms/api/static_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule CMS.API.StaticTest do
defmodule CMS.Api.StaticTest do
use ExUnit.Case
import CMS.API.Static
import CMS.Api.Static

describe "view/2" do
test "stubs /news when given a page parameter and returns valid json" do
Expand Down
2 changes: 1 addition & 1 deletion test/cms/page/basic_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule CMS.Page.BasicTest do

import CMS.APITestHelpers, only: [update_api_response: 3]

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Page.Basic
alias CMS.Partial.MenuLinks
alias Phoenix.HTML
Expand Down
2 changes: 1 addition & 1 deletion test/cms/page/event_agenda_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule CMS.Page.EventAgendaTest do
use ExUnit.Case, async: true

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Page.EventAgenda
alias CMS.Partial.Paragraph.AgendaTopic

Expand Down
2 changes: 1 addition & 1 deletion test/cms/page/event_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule CMS.Page.EventTest do
import CMS.Page.Event
import Phoenix.HTML, only: [safe_to_string: 1]

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Page.Event
alias Phoenix.HTML

Expand Down
2 changes: 1 addition & 1 deletion test/cms/page/landing_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule CMS.Page.LandingTest do
use ExUnit.Case, async: true

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Field.Image
alias CMS.Page.Landing

Expand Down
2 changes: 1 addition & 1 deletion test/cms/page/news_entry_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule CMS.Page.NewsEntryTest do
use ExUnit.Case

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Page.NewsEntry
alias Phoenix.HTML

Expand Down
2 changes: 1 addition & 1 deletion test/cms/page/person_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule CMS.Page.PersonTest do

import Phoenix.HTML, only: [safe_to_string: 1]

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Field.Image
alias CMS.Page.Person

Expand Down
2 changes: 1 addition & 1 deletion test/cms/page/project_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule CMS.Page.ProjectTest do
update_api_response_whole_field: 3
]

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Field.{File, Image}
alias CMS.Page.Project
alias CMS.Partial.Paragraph.CustomHTML
Expand Down
2 changes: 1 addition & 1 deletion test/cms/page/project_update_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule CMS.Page.ProjectUpdateTest do

import CMS.APITestHelpers, only: [update_api_response_whole_field: 3]

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Field.Image
alias CMS.Page.ProjectUpdate
alias Phoenix.HTML
Expand Down
2 changes: 1 addition & 1 deletion test/cms/page/redirect_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule CMS.Page.RedirectTest do
use ExUnit.Case, async: true

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Field.Link
alias CMS.Page.Redirect

Expand Down
2 changes: 1 addition & 1 deletion test/cms/page_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule PageTest do
use ExUnit.Case, async: true

alias CMS.{
API.Static,
Api.Static,
Page,
Partial.Paragraph.ContentList,
Partial.Teaser
Expand Down
2 changes: 1 addition & 1 deletion test/cms/paragraph_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule CMS.ParagraphTest do
import CMS.Partial.Paragraph
import Phoenix.HTML, only: [safe_to_string: 1]

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Field.{File, Image, Link}

alias CMS.Partial.Paragraph.{
Expand Down
2 changes: 1 addition & 1 deletion test/cms/partial/banner_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule CMS.Partial.BannerTest do
use ExUnit.Case, async: true

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Field.{Image, Link}
alias CMS.Partial.Banner

Expand Down
2 changes: 1 addition & 1 deletion test/cms/partial/menu_links_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule CMS.Partial.MenuLinksTest do

import CMS.Partial.MenuLinks

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Field.Link
alias CMS.Partial.MenuLinks

Expand Down
2 changes: 1 addition & 1 deletion test/cms/partial/teaser_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule CMS.Partial.TeaserTest do
use ExUnit.Case, async: true

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Field.Image
alias CMS.Partial.Teaser

Expand Down
2 changes: 1 addition & 1 deletion test/cms/partial/whats_happening_item_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule CMS.Partial.WhatsHappeningItemTest do
use ExUnit.Case, async: true

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Field.{Image, Link}
alias CMS.Partial.WhatsHappeningItem

Expand Down
32 changes: 22 additions & 10 deletions test/dotcom_web/controllers/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,12 @@ defmodule DotcomWeb.ControllerHelpersTest do

describe "forward_static_file/2" do
test "returns a 404 if there's an error" do
expect(HTTPoison.Mock, :get, fn _, _, _ ->
{:error, %HTTPoison.Response{status_code: 500, body: "error on remote server"}}
expect(Req.Mock, :new, fn _ ->
%Req.Request{}
end)

expect(Req.Mock, :get, fn _, _ ->
{:ok, %Req.Response{status: 500, body: "error on remote server"}}
end)

response =
Expand All @@ -315,8 +319,12 @@ defmodule DotcomWeb.ControllerHelpersTest do
end

test "returns a 404 if the remote side returns a 404" do
expect(HTTPoison.Mock, :get, fn _, _, _ ->
{:ok, %HTTPoison.Response{status_code: 404, body: "not found"}}
expect(Req.Mock, :new, fn _ ->
%Req.Request{}
end)

expect(Req.Mock, :get, fn _, _ ->
{:ok, %Req.Response{status: 404, body: "not found"}}
end)

response =
Expand All @@ -328,14 +336,18 @@ defmodule DotcomWeb.ControllerHelpersTest do

test "returns the body and headers from the response if it's a 200" do
headers = [
{"Content-Type", "text/plain"},
{"ETag", "tag"},
{"Content-Length", "6"},
{"Date", "Tue, 13 Nov 2018 00:00:00 EST"}
{"content-type", "text/plain"},
{"etag", "tag"},
{"content-length", "6"},
{"date", "Tue, 13 Nov 2018 00:00:00 EST"}
]

expect(HTTPoison.Mock, :get, fn _, _, _ ->
{:ok, %HTTPoison.Response{status_code: 200, body: "a file", headers: headers}}
expect(Req.Mock, :new, fn _ ->
%Req.Request{}
end)

expect(Req.Mock, :get, fn _, _ ->
{:ok, %Req.Response{status: 200, body: "a file", headers: headers}}
end)

response =
Expand Down
10 changes: 7 additions & 3 deletions test/dotcom_web/controllers/static_file_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ defmodule DotcomWeb.StaticFileControllerTest do

describe "index/2" do
test "forwards files from config:cms:drupal:cms_root" do
expect(HTTPoison.Mock, :get, fn url, _, _ ->
assert url == Application.get_env(:dotcom, :drupal)[:cms_root] <> "/path"
expect(Req.Mock, :new, fn _ ->
%Req.Request{}
end)

expect(Req.Mock, :get, fn _, [url: url] ->
assert url == Application.get_env(:dotcom, :cms_api)[:base_url] <> "/path"

{:ok, %HTTPoison.Response{status_code: 200, body: "file from drupal"}}
{:ok, %Req.Response{status: 200, body: "file from drupal"}}
end)

conn = %{build_conn() | request_path: "/path"}
Expand Down
2 changes: 1 addition & 1 deletion test/dotcom_web/views/cms_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule DotcomWeb.CMSViewTest do
import DotcomWeb.CMSView
import CMS.Helpers, only: [parse_iso_datetime: 1]

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Field.File
alias CMS.Page.Basic
alias CMS.Partial.Paragraph.CustomHTML
Expand Down
2 changes: 1 addition & 1 deletion test/dotcom_web/views/teaser_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule DotcomWeb.TeaserViewTest do

import DotcomWeb.CMS.TeaserView

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Partial.Teaser

@dummy_teaser %Teaser{
Expand Down
2 changes: 1 addition & 1 deletion test/support/cms/factory.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule CMS.Factory do
@moduledoc false

alias CMS.API.Static
alias CMS.Api.Static
alias CMS.Page.{Event, NewsEntry, Person, Project, ProjectUpdate}
alias CMS.Partial.Teaser

Expand Down

0 comments on commit b26c837

Please sign in to comment.