forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermissionRequestResultTest.java
More file actions
73 lines (60 loc) · 2.43 KB
/
Copy pathPermissionRequestResultTest.java
File metadata and controls
73 lines (60 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import com.github.copilot.rpc.PermissionRequestResult;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.annotation.JsonInclude;
/**
* Tests for {@link PermissionRequestResult} factory methods and feedback field.
*/
public class PermissionRequestResultTest {
private static final ObjectMapper MAPPER = JsonMapper.builder().serializationInclusion(JsonInclude.Include.NON_NULL)
.build();
@Test
void testApproveOnce() {
var result = PermissionRequestResult.approveOnce();
assertEquals("approve-once", result.getKind());
assertNull(result.getFeedback());
}
@Test
void testRejectWithFeedback() {
var result = PermissionRequestResult.reject("Not allowed");
assertEquals("reject", result.getKind());
assertEquals("Not allowed", result.getFeedback());
}
@Test
void testRejectWithoutFeedback() {
var result = PermissionRequestResult.reject(null);
assertEquals("reject", result.getKind());
assertNull(result.getFeedback());
}
@Test
void testUserNotAvailable() {
var result = PermissionRequestResult.userNotAvailable();
assertEquals("user-not-available", result.getKind());
assertNull(result.getFeedback());
}
@Test
void testNoResult() {
var result = PermissionRequestResult.noResult();
assertEquals("no-result", result.getKind());
assertNull(result.getFeedback());
}
@Test
void testFeedbackSerialized() throws Exception {
var result = PermissionRequestResult.reject("Unsafe operation");
var json = MAPPER.writeValueAsString(result);
assertTrue(json.contains("\"feedback\":\"Unsafe operation\""));
assertTrue(json.contains("\"kind\":\"reject\""));
}
@Test
void testFeedbackNotSerializedWhenNull() throws Exception {
var result = PermissionRequestResult.approveOnce();
var json = MAPPER.writeValueAsString(result);
assertFalse(json.contains("feedback"));
}
}