-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stefan Wilke
committed
Nov 21, 2023
1 parent
76a4fae
commit 3446183
Showing
10 changed files
with
620 additions
and
33 deletions.
There are no files selected for viewing
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
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
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
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
119 changes: 119 additions & 0 deletions
119
backend/src/test/java/com/github/binpastes/paste/api/OneTimePastesIT.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.github.binpastes.paste.api; | ||
|
||
import com.github.binpastes.paste.domain.Paste; | ||
import com.github.binpastes.paste.domain.PasteRepository; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.CacheControl; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest | ||
@AutoConfigureWebTestClient | ||
class OneTimePastesIT { | ||
|
||
@Autowired | ||
private WebTestClient webClient; | ||
|
||
@Autowired | ||
private PasteRepository pasteRepository; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
pasteRepository.deleteAll().block(); | ||
} | ||
|
||
@Test | ||
@DisplayName("GET /{pasteId} - one-time paste is never cached") | ||
void getOneTimePaste() { | ||
var oneTimePaste = givenOneTimePaste(); | ||
|
||
webClient.get() | ||
.uri("/api/v1/paste/" + oneTimePaste.getId()) | ||
.exchange() | ||
.expectStatus().isOk() | ||
.expectHeader().cacheControl(CacheControl.noStore()); | ||
} | ||
|
||
@Test | ||
@DisplayName("GET /{pasteId} - one-time paste is read-once") | ||
void getOneTimePasteTwice() { | ||
var oneTimePaste = givenOneTimePaste(); | ||
|
||
webClient.get() | ||
.uri("/api/v1/paste/" + oneTimePaste.getId()) | ||
.exchange() | ||
.expectStatus().isOk(); | ||
|
||
webClient.get() | ||
.uri("/api/v1/paste/" + oneTimePaste.getId()) | ||
.exchange() | ||
.expectStatus().isNotFound(); | ||
} | ||
|
||
@Test | ||
@DisplayName("GET / - one-time paste is never listed") | ||
void findAllPastes() { | ||
givenOneTimePaste(); | ||
|
||
assertThat(pasteRepository.count().block()).isOne(); | ||
webClient.get() | ||
.uri("/api/v1/paste/") | ||
.exchange() | ||
.expectStatus().isOk() | ||
.expectBody().jsonPath("pastes", emptyList()); | ||
} | ||
|
||
@Test | ||
@DisplayName("GET /search - one-time paste cannot be searched for") | ||
void searchAllPastes() { | ||
givenOneTimePaste(); | ||
|
||
assertThat(pasteRepository.count().block()).isOne(); | ||
webClient.get() | ||
.uri("/api/v1/paste/search?term={term}", "ipsum") | ||
.exchange() | ||
.expectStatus().isOk() | ||
.expectBody().jsonPath("pastes", emptyList()); | ||
} | ||
|
||
@Test | ||
@DisplayName("DELETE /{pasteId} - one-time paste might always be deleted before reading") | ||
void deleteOneTimePaste() { | ||
var oneTimePaste = givenOneTimePaste(); | ||
|
||
webClient.delete() | ||
.uri("/api/v1/paste/" + oneTimePaste.getId()) | ||
.exchange() | ||
.expectStatus().isNoContent() | ||
.expectBody().isEmpty(); | ||
|
||
webClient.get() | ||
.uri("/api/v1/paste/" + oneTimePaste.getId()) | ||
.exchange() | ||
.expectStatus().isNotFound(); | ||
} | ||
|
||
private Paste givenOneTimePaste() { | ||
return givenOneTimePaste( | ||
Paste.newInstance( | ||
"someTitle", | ||
"Lorem ipsum dolor sit amet", | ||
null, | ||
false, | ||
Paste.PasteExposure.ONCE, | ||
"1.1.1.1" | ||
) | ||
); | ||
} | ||
|
||
private Paste givenOneTimePaste(Paste paste) { | ||
return pasteRepository.save(paste).block(); | ||
} | ||
} |
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
Oops, something went wrong.