-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add CommunityMomentCallout_Claim GQL call
- Loading branch information
Showing
9 changed files
with
257 additions
and
0 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
23 changes: 23 additions & 0 deletions
23
...miner/miner/api/gql/data/communitymomentcalloutclaim/CommunityMomentCalloutClaimData.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,23 @@ | ||
package fr.raksrinana.channelpointsminer.miner.api.gql.data.communitymomentcalloutclaim; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import fr.raksrinana.channelpointsminer.miner.api.gql.data.types.ClaimCommunityMomentPayload; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class CommunityMomentCalloutClaimData{ | ||
@JsonProperty("claimCommunityMoment") | ||
@NotNull | ||
private ClaimCommunityMomentPayload moment; | ||
} |
27 changes: 27 additions & 0 deletions
27
.../miner/api/gql/data/communitymomentcalloutclaim/CommunityMomentCalloutClaimOperation.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,27 @@ | ||
package fr.raksrinana.channelpointsminer.miner.api.gql.data.communitymomentcalloutclaim; | ||
|
||
import fr.raksrinana.channelpointsminer.miner.api.gql.data.GQLResponse; | ||
import fr.raksrinana.channelpointsminer.miner.api.gql.data.IGQLOperation; | ||
import fr.raksrinana.channelpointsminer.miner.api.gql.data.PersistedQueryExtension; | ||
import kong.unirest.core.GenericType; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@Getter | ||
@EqualsAndHashCode(callSuper = true) | ||
@ToString | ||
public class CommunityMomentCalloutClaimOperation extends IGQLOperation<CommunityMomentCalloutClaimData>{ | ||
public CommunityMomentCalloutClaimOperation(@NotNull String momentId){ | ||
super("CommunityMomentCallout_Claim"); | ||
addPersistedQueryExtension(new PersistedQueryExtension(1, "e2d67415aead910f7f9ceb45a77b750a1e1d9622c936d832328a0689e054db62")); | ||
addVariable("input", InputData.builder().momentId(momentId).build()); | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public GenericType<GQLResponse<CommunityMomentCalloutClaimData>> getResponseType(){ | ||
return new GenericType<>(){}; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ksrinana/channelpointsminer/miner/api/gql/data/communitymomentcalloutclaim/InputData.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,20 @@ | ||
package fr.raksrinana.channelpointsminer.miner.api.gql.data.communitymomentcalloutclaim; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode | ||
@ToString | ||
public class InputData{ | ||
@JsonProperty("momentID") | ||
private String momentId; | ||
} |
30 changes: 30 additions & 0 deletions
30
...r/raksrinana/channelpointsminer/miner/api/gql/data/types/ClaimCommunityMomentPayload.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,30 @@ | ||
package fr.raksrinana.channelpointsminer.miner.api.gql.data.types; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import fr.raksrinana.channelpointsminer.miner.util.json.UnknownDeserializer; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@JsonTypeName("ClaimCommunityMomentPayload") | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode(callSuper = true) | ||
@ToString | ||
public class ClaimCommunityMomentPayload extends GQLType{ | ||
@JsonProperty("moment") | ||
@Nullable | ||
private CommunityMoment moment; | ||
@JsonProperty("error") | ||
@JsonDeserialize(using = UnknownDeserializer.class) | ||
@Nullable | ||
private Object error; | ||
} |
24 changes: 24 additions & 0 deletions
24
.../main/java/fr/raksrinana/channelpointsminer/miner/api/gql/data/types/CommunityMoment.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,24 @@ | ||
package fr.raksrinana.channelpointsminer.miner.api.gql.data.types; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@JsonTypeName("CommunityMoment") | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@EqualsAndHashCode(callSuper = true) | ||
@ToString | ||
public class CommunityMoment extends GQLType{ | ||
@JsonProperty("id") | ||
@NotNull | ||
private String id; | ||
} |
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
107 changes: 107 additions & 0 deletions
107
...t/java/fr/raksrinana/channelpointsminer/miner/api/gql/GQLApiClaimCommunityMomentTest.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,107 @@ | ||
package fr.raksrinana.channelpointsminer.miner.api.gql; | ||
|
||
import fr.raksrinana.channelpointsminer.miner.api.gql.data.GQLResponse; | ||
import fr.raksrinana.channelpointsminer.miner.api.gql.data.communitymomentcalloutclaim.CommunityMomentCalloutClaimData; | ||
import fr.raksrinana.channelpointsminer.miner.api.gql.data.types.ClaimCommunityMomentPayload; | ||
import fr.raksrinana.channelpointsminer.miner.api.gql.data.types.CommunityMoment; | ||
import fr.raksrinana.channelpointsminer.miner.api.passport.TwitchLogin; | ||
import fr.raksrinana.channelpointsminer.miner.tests.TestUtils; | ||
import fr.raksrinana.channelpointsminer.miner.tests.UnirestMockExtension; | ||
import kong.unirest.core.MockClient; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import java.util.Map; | ||
import static kong.unirest.core.HttpMethod.POST; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@ExtendWith(UnirestMockExtension.class) | ||
class GQLApiClaimCommunityMomentTest{ | ||
private static final String ACCESS_TOKEN = "access-token"; | ||
private static final String MOMENT_ID = "moment-id"; | ||
private static final String VALID_QUERY = "{\"extensions\":{\"persistedQuery\":{\"sha256Hash\":\"e2d67415aead910f7f9ceb45a77b750a1e1d9622c936d832328a0689e054db62\",\"version\":1}},\"operationName\":\"CommunityMomentCallout_Claim\",\"variables\":{\"input\":{\"momentID\":\"%s\"}}}"; | ||
|
||
@InjectMocks | ||
private GQLApi tested; | ||
|
||
@Mock | ||
private TwitchLogin twitchLogin; | ||
|
||
@BeforeEach | ||
void setUp(){ | ||
when(twitchLogin.getAccessToken()).thenReturn(ACCESS_TOKEN); | ||
} | ||
|
||
@Test | ||
void nominalClaimed(MockClient unirest){ | ||
var expected = GQLResponse.<CommunityMomentCalloutClaimData> builder() | ||
.extensions(Map.of( | ||
"durationMilliseconds", 9, | ||
"operationName", "CommunityMomentCallout_Claim", | ||
"requestID", "request-id" | ||
)) | ||
.data(CommunityMomentCalloutClaimData.builder() | ||
.moment(ClaimCommunityMomentPayload.builder() | ||
.moment(CommunityMoment.builder() | ||
.id(MOMENT_ID) | ||
.build()) | ||
.build()) | ||
.build()) | ||
.build(); | ||
|
||
unirest.expect(POST, "https://gql.twitch.tv/gql") | ||
.header("Authorization", "OAuth " + ACCESS_TOKEN) | ||
.body(VALID_QUERY.formatted(MOMENT_ID)) | ||
.thenReturn(TestUtils.getAllResourceContent("api/gql/communityMomentCalloutClaim_success.json")) | ||
.withStatus(200); | ||
|
||
assertThat(tested.claimCommunityMoment(MOMENT_ID)).isPresent().get().isEqualTo(expected); | ||
|
||
unirest.verifyAll(); | ||
} | ||
|
||
@Test | ||
void invalidCredentials(MockClient unirest){ | ||
unirest.expect(POST, "https://gql.twitch.tv/gql") | ||
.header("Authorization", "OAuth " + ACCESS_TOKEN) | ||
.body(VALID_QUERY.formatted(MOMENT_ID)) | ||
.thenReturn(TestUtils.getAllResourceContent("api/gql/invalidAuth.json")) | ||
.withStatus(401); | ||
|
||
assertThrows(RuntimeException.class, () -> tested.claimCommunityMoment(MOMENT_ID)); | ||
|
||
unirest.verifyAll(); | ||
} | ||
|
||
@Test | ||
void invalidRequest(MockClient unirest){ | ||
unirest.expect(POST, "https://gql.twitch.tv/gql") | ||
.header("Authorization", "OAuth " + ACCESS_TOKEN) | ||
.body(VALID_QUERY.formatted(MOMENT_ID)) | ||
.thenReturn(TestUtils.getAllResourceContent("api/gql/invalidRequest.json")) | ||
.withStatus(200); | ||
|
||
assertThat(tested.claimCommunityMoment(MOMENT_ID)).isEmpty(); | ||
|
||
unirest.verifyAll(); | ||
} | ||
|
||
@Test | ||
void invalidResponse(MockClient unirest){ | ||
unirest.expect(POST, "https://gql.twitch.tv/gql") | ||
.header("Authorization", "OAuth " + ACCESS_TOKEN) | ||
.body(VALID_QUERY.formatted(MOMENT_ID)) | ||
.thenReturn() | ||
.withStatus(500); | ||
|
||
assertThat(tested.claimCommunityMoment(MOMENT_ID)).isEmpty(); | ||
|
||
unirest.verifyAll(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
miner/src/test/resources/api/gql/communityMomentCalloutClaim_success.json
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,17 @@ | ||
{ | ||
"data" : { | ||
"claimCommunityMoment" : { | ||
"moment" : { | ||
"id" : "moment-id", | ||
"__typename" : "CommunityMoment" | ||
}, | ||
"error" : null, | ||
"__typename" : "ClaimCommunityMomentPayload" | ||
} | ||
}, | ||
"extensions" : { | ||
"durationMilliseconds" : 9, | ||
"operationName" : "CommunityMomentCallout_Claim", | ||
"requestID" : "request-id" | ||
} | ||
} |