Skip to content

Commit a927159

Browse files
kuraunrstoyanchev
authored andcommitted
Add mutationUpdateSalaryTest
Fixed the attribute value salary of UpdateSalaryInput of schema.graphqls to the name of SalaryInput object. Also enabled @secured. See gh-367
1 parent 5905f02 commit a927159

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SalaryInput.java

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public class SalaryInput {
2323

2424
private BigDecimal newSalary;
2525

26+
public SalaryInput(String employeeId, BigDecimal newSalary) {
27+
this.employeeId = employeeId;
28+
this.newSalary = newSalary;
29+
}
30+
2631
public String getEmployeeId() {
2732
return employeeId;
2833
}

samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SecurityConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
@Configuration
1616
@EnableWebSecurity
17-
@EnableGlobalMethodSecurity(prePostEnabled = true)
17+
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
1818
public class SecurityConfig {
1919

2020
@Bean

samples/webmvc-http-security/src/main/resources/graphql/schema.graphqls

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Employee {
1414

1515
input UpdateSalaryInput {
1616
employeeId: ID!
17-
salary: String!
17+
newSalary: String!
1818
}
1919
type UpdateSalaryPayload {
2020
success: Boolean!

samples/webmvc-http-security/src/test/java/io/spring/sample/graphql/WebMvcHttpSecuritySampleTests.java

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.springframework.graphql.execution.ErrorType;
99
import org.springframework.graphql.test.tester.WebGraphQlTester;
1010

11+
import java.math.BigDecimal;
12+
1113
import static org.assertj.core.api.Assertions.assertThat;
1214
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1315

@@ -72,6 +74,21 @@ void canNotQuerySalary() {
7274
});
7375
}
7476

77+
@Test
78+
void canNotMutationUpdateSalary() {
79+
WebGraphQlTester tester = this.graphQlTester.mutate().build();
80+
SalaryInput salaryInput = new SalaryInput("1", BigDecimal.valueOf(44));
81+
82+
tester.documentName("updateSalary")
83+
.variable("salaryInput", salaryInput)
84+
.execute()
85+
.errors()
86+
.satisfy(errors -> {
87+
assertThat(errors).hasSize(1);
88+
assertThat(errors.get(0).getErrorType()).isEqualTo(ErrorType.UNAUTHORIZED);
89+
});
90+
}
91+
7592
@Test
7693
void canQuerySalaryAsAdmin() {
7794

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
mutation updateSalary($salaryInput: UpdateSalaryInput!) {
2+
updateSalary(input: $salaryInput) {
3+
success
4+
employee {
5+
id
6+
name
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)