|
115 | 115 | (t/testing "Test get all articles default database query"
|
116 | 116 | (with-redefs [sql/query (fn [_ q] q)]
|
117 | 117 | (let [[query limit] (sut/get-all-articles nil)]
|
118 |
| - (t/is (= "SELECT id, user_id, title, featured_image, updated_on, description FROM articles ORDER BY updated_on DESC LIMIT ?" query)) |
| 118 | + (t/is (= (str "SELECT id, user_id, title, featured_image, updated_on, description " |
| 119 | + "FROM articles ORDER BY updated_on DESC LIMIT ?") query)) |
119 | 120 | (t/is (= 100 limit))))))
|
120 | 121 |
|
121 | 122 | (t/deftest get-all-articles-test-query-with-limit
|
|
130 | 131 | (with-redefs [sql/query (fn [_ q] q)]
|
131 | 132 | (let [number-param 30
|
132 | 133 | [query number] (sut/get-latest-full-sized-articles nil number-param)]
|
133 |
| - (t/is (= "SELECT id, user_id, title, body, featured_image, created_on, updated_on, description FROM articles ORDER BY updated_on DESC LIMIT ?" query)) |
| 134 | + (t/is (= (str "SELECT id, user_id, title, body, featured_image, created_on, updated_on, description " |
| 135 | + "FROM articles ORDER BY updated_on DESC LIMIT ?") query)) |
134 | 136 | (t/is (= number-param number ))))))
|
135 | 137 |
|
136 | 138 | (t/deftest get-user-articles-test-default-query
|
137 | 139 | (t/testing "Test get user articles default database query"
|
138 | 140 | (with-redefs [sql/query (fn [_ q] q)]
|
139 | 141 | (let [user-id-param 42
|
140 | 142 | [query user-id limit] (sut/get-user-articles nil user-id-param)]
|
141 |
| - (t/is (= "SELECT id, user_id, title, featured_image, updated_on, description FROM articles WHERE user_id = ? ORDER BY updated_on DESC LIMIT ?" query)) |
| 143 | + (t/is (= (str "SELECT id, user_id, title, featured_image, updated_on, description " |
| 144 | + "FROM articles " |
| 145 | + "WHERE user_id = ? ORDER BY updated_on DESC LIMIT ?") query)) |
142 | 146 | (t/is (= limit 100))
|
143 | 147 | (t/is (= user-id user-id-param))))))
|
144 | 148 |
|
|
165 | 169 | (with-redefs [sql/query (spy/spy)]
|
166 | 170 | (sut/get-last-featured-article nil)
|
167 | 171 | (let [[[_ [query limit]]] (spy/calls sql/query)]
|
168 |
| - (t/is (= "SELECT id, user_id, title, featured_image, updated_on, description FROM articles WHERE is_main_featured = TRUE ORDER BY updated_on DESC LIMIT ?" query)) |
| 172 | + (t/is (= (str "SELECT id, user_id, title, featured_image, updated_on, description " |
| 173 | + "FROM articles " |
| 174 | + "WHERE is_main_featured = TRUE " |
| 175 | + "ORDER BY updated_on DESC LIMIT ?") query)) |
169 | 176 | (t/is (= 1 limit))))))
|
170 | 177 |
|
171 | 178 | (t/deftest get-last-featured-article-test-no-results
|
|
179 | 186 | (with-redefs [sql/query (fn [_ _] res)]
|
180 | 187 | (t/is (= (first res) (sut/get-last-featured-article nil)))))))
|
181 | 188 |
|
| 189 | +(t/deftest get-last-featured-articles-test-query |
| 190 | + (t/testing "Get latest featured article list database query" |
| 191 | + (with-redefs [sql/query (spy/spy)] |
| 192 | + (let [limit-param 3 |
| 193 | + _ (sut/get-last-featured-articles nil limit-param) |
| 194 | + [[_ [query limit offset]]] (spy/calls sql/query)] |
| 195 | + (t/is (= limit-param limit)) |
| 196 | + (t/is (= 1 offset)) |
| 197 | + (t/is (= (str "SELECT id, user_id, title, featured_image, updated_on, description " |
| 198 | + "FROM articles " |
| 199 | + "WHERE is_main_featured = TRUE " |
| 200 | + "ORDER BY updated_on DESC LIMIT ? OFFSET ?") query)))))) |
| 201 | + |
| 202 | +(t/deftest get-last-featured-articles-test-no-results |
| 203 | + (t/testing "Get latest featured article list no results from database" |
| 204 | + (with-redefs [sql/query (spy/mock (fn [_ _] []))] |
| 205 | + (let [res (sut/get-last-featured-articles nil 3)] |
| 206 | + (t/is (= [] res)))))) |
| 207 | + |
182 | 208 | (t/deftest delete-article-test-table-name
|
183 | 209 | (t/testing "Delete article database table name"
|
184 | 210 | (with-redefs [sql/delete! (fn [_ t _] t)]
|
|
0 commit comments