logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

openapi_spec_test.exs (1618B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Mix.Tasks.Pleroma.OpenapiSpecTest do
  5. use Pleroma.DataCase, async: true
  6. alias Mix.Tasks.Pleroma.OpenapiSpec
  7. @spec_base %{
  8. "paths" => %{
  9. "/cofe" => %{
  10. "get" => %{
  11. "operationId" => "Some.operation",
  12. "tags" => []
  13. }
  14. },
  15. "/mew" => %{
  16. "post" => %{
  17. "operationId" => "Another.operation",
  18. "tags" => ["mew mew"]
  19. }
  20. }
  21. },
  22. "x-tagGroups" => [
  23. %{
  24. "name" => "mew",
  25. "tags" => ["mew mew", "abc"]
  26. },
  27. %{
  28. "name" => "lol",
  29. "tags" => ["lol lol", "xyz"]
  30. }
  31. ]
  32. }
  33. describe "check_specs/1" do
  34. test "Every operation must have a tag" do
  35. assert {:error, ["Some.operation (get /cofe): No tags specified"]} ==
  36. OpenapiSpec.check_specs(@spec_base)
  37. end
  38. test "Every tag must be in tag groups" do
  39. spec =
  40. @spec_base
  41. |> put_in(["paths", "/cofe", "get", "tags"], ["abc", "def", "not specified"])
  42. assert {:error,
  43. [
  44. "Some.operation (get /cofe): Tags #{inspect(["def", "not specified"])} not available. Please add it in \"x-tagGroups\" in Pleroma.Web.ApiSpec"
  45. ]} == OpenapiSpec.check_specs(spec)
  46. end
  47. test "No errors if ok" do
  48. spec =
  49. @spec_base
  50. |> put_in(["paths", "/cofe", "get", "tags"], ["abc", "mew mew"])
  51. assert :ok == OpenapiSpec.check_specs(spec)
  52. end
  53. end
  54. end