|
1 | 1 | package com.azavea.stac4s.api.client |
2 | 2 |
|
3 | | -import com.azavea.stac4s.testing.JsInstances |
| 3 | +import com.azavea.stac4s.{ItemCollection, StacCollection, StacItem} |
4 | 4 |
|
5 | 5 | import cats.syntax.either._ |
6 | 6 | import eu.timepit.refined.types.all.NonEmptyString |
7 | 7 | import io.circe.JsonObject |
8 | 8 | import io.circe.syntax._ |
| 9 | +import org.scalacheck.Arbitrary |
9 | 10 | import org.scalatest.BeforeAndAfterAll |
10 | 11 | import org.scalatest.funspec.AnyFunSpec |
11 | 12 | import org.scalatest.matchers.should.Matchers |
| 13 | +import sttp.client3.Response |
12 | 14 | import sttp.client3.testing.SttpBackendStub |
13 | | -import sttp.client3.{Response, UriContext} |
14 | 15 | import sttp.model.Method |
15 | 16 | import sttp.monad.EitherMonad |
16 | 17 |
|
17 | | -class StacClientSpec extends AnyFunSpec with Matchers with JsInstances with BeforeAndAfterAll { |
| 18 | +trait BaseSttpStacClientSpec extends AnyFunSpec with Matchers with BeforeAndAfterAll { |
| 19 | + |
| 20 | + def arbCollectionShort: Arbitrary[StacCollection] |
| 21 | + def arbItemCollectionShort: Arbitrary[ItemCollection] |
| 22 | + def arbItemShort: Arbitrary[StacItem] |
| 23 | + |
| 24 | + def client: BaseSttpStacClient[Either[Throwable, *]] |
18 | 25 |
|
19 | 26 | lazy val backend = |
20 | 27 | SttpBackendStub(EitherMonad) |
@@ -67,41 +74,41 @@ class StacClientSpec extends AnyFunSpec with Matchers with JsInstances with Befo |
67 | 74 | .asRight |
68 | 75 | } |
69 | 76 |
|
70 | | - describe("StacClientSpec") { |
| 77 | + describe("SttpStacClientSpec") { |
71 | 78 | it("search") { |
72 | | - SttpStacClient(backend, uri"http://localhost:9090").search |
| 79 | + client.search |
73 | 80 | .valueOr(throw _) |
74 | 81 | .size should be > 0 |
75 | 82 | } |
76 | 83 |
|
77 | 84 | it("collections") { |
78 | | - SttpStacClient(backend, uri"http://localhost:9090").collections |
| 85 | + client.collections |
79 | 86 | .valueOr(throw _) |
80 | 87 | .size should be > 0 |
81 | 88 | } |
82 | 89 |
|
83 | 90 | it("items") { |
84 | | - SttpStacClient(backend, uri"http://localhost:9090") |
| 91 | + client |
85 | 92 | .items(NonEmptyString.unsafeFrom("collection_id")) |
86 | 93 | .valueOr(throw _) |
87 | 94 | .size should be > 0 |
88 | 95 | } |
89 | 96 |
|
90 | 97 | it("item") { |
91 | | - SttpStacClient(backend, uri"http://localhost:9090") |
| 98 | + client |
92 | 99 | .item(NonEmptyString.unsafeFrom("collection_id"), NonEmptyString.unsafeFrom("item_id")) |
93 | 100 | .valueOr(throw _) |
94 | 101 | .size should be > 0 |
95 | 102 | } |
96 | 103 |
|
97 | 104 | it("itemCreate") { |
98 | | - SttpStacClient(backend, uri"http://localhost:9090") |
| 105 | + client |
99 | 106 | .itemCreate(NonEmptyString.unsafeFrom("collection_id"), arbItemShort.arbitrary.sample.get) |
100 | 107 | .map(_.id should not be empty) |
101 | 108 | } |
102 | 109 |
|
103 | 110 | it("collectionCreate") { |
104 | | - SttpStacClient(backend, uri"http://localhost:9090") |
| 111 | + client |
105 | 112 | .collectionCreate(arbCollectionShort.arbitrary.sample.get) |
106 | 113 | .map(_.id should not be empty) |
107 | 114 | } |
|
0 commit comments