Skip to content

Commit ebc9164

Browse files
committed
more int test
1 parent d08b3cd commit ebc9164

1 file changed

Lines changed: 221 additions & 0 deletions

File tree

test/integration/index.spec.js

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,4 +1048,225 @@ describe("Test Apollo Service", () => {
10481048
await broker.stop();
10491049
});
10501050
});
1051+
1052+
describe("Test schema interfaces & unions", () => {
1053+
it("should handle interface and union types", async () => {
1054+
const { broker, url } = await startService();
1055+
1056+
await broker.createService({
1057+
name: "content",
1058+
settings: {
1059+
graphql: {
1060+
interface: `
1061+
interface Node {
1062+
id: ID!
1063+
}
1064+
`,
1065+
union: `
1066+
union SearchResult = Post | User
1067+
`,
1068+
type: `
1069+
type Post implements Node {
1070+
id: ID!
1071+
title: String!
1072+
}
1073+
type User implements Node {
1074+
id: ID!
1075+
name: String!
1076+
}
1077+
`
1078+
}
1079+
},
1080+
actions: {
1081+
search: {
1082+
graphql: {
1083+
query: "search(term: String!): [SearchResult!]!"
1084+
},
1085+
handler(ctx) {
1086+
if (ctx.params.term === "post") {
1087+
return [{ __typename: "Post", id: "1", title: "Test Post" }];
1088+
}
1089+
return [{ __typename: "User", id: "1", name: "Test User" }];
1090+
}
1091+
}
1092+
}
1093+
});
1094+
1095+
const res = await call(url, {
1096+
query: `{
1097+
search(term: "post") {
1098+
... on Post {
1099+
id
1100+
title
1101+
}
1102+
... on User {
1103+
id
1104+
name
1105+
}
1106+
}
1107+
}`
1108+
});
1109+
1110+
expect(res.status).toBe(200);
1111+
expect(await res.json()).toEqual({
1112+
data: {
1113+
search: [
1114+
{
1115+
id: "1",
1116+
title: "Test Post"
1117+
}
1118+
]
1119+
}
1120+
});
1121+
1122+
const res2 = await call(url, {
1123+
query: `{
1124+
search(term: "user") {
1125+
... on Post {
1126+
id
1127+
title
1128+
}
1129+
... on User {
1130+
id
1131+
name
1132+
}
1133+
}
1134+
}`
1135+
});
1136+
1137+
expect(res2.status).toBe(200);
1138+
expect(await res2.json()).toEqual({
1139+
data: {
1140+
search: [
1141+
{
1142+
id: "1",
1143+
name: "Test User"
1144+
}
1145+
]
1146+
}
1147+
});
1148+
1149+
await broker.stop();
1150+
});
1151+
});
1152+
1153+
describe("Test service lifecycle and error handling", () => {
1154+
it("should not publish private action", async () => {
1155+
const { broker, url } = await startService({
1156+
checkActionVisibility: true
1157+
});
1158+
1159+
await broker.createService({
1160+
name: "visibility-test",
1161+
actions: {
1162+
publishedAction: {
1163+
visibility: "published",
1164+
graphql: {
1165+
query: "publishedData: String!"
1166+
},
1167+
handler() {
1168+
return "Published data";
1169+
}
1170+
},
1171+
publicAction: {
1172+
visibility: "public",
1173+
graphql: {
1174+
query: "publicData: String!"
1175+
},
1176+
handler() {
1177+
return "Public data";
1178+
}
1179+
},
1180+
protectedAction: {
1181+
visibility: "protected",
1182+
graphql: {
1183+
query: "protectedData: String!"
1184+
},
1185+
handler() {
1186+
return "Protected data";
1187+
}
1188+
}
1189+
}
1190+
});
1191+
1192+
// Published action should be available
1193+
const res = await call(url, {
1194+
query: "{ publishedData }"
1195+
});
1196+
expect(res.status).toBe(200);
1197+
1198+
// Public action should not be in schema
1199+
const res2 = await call(url, {
1200+
query: "{ publicData }"
1201+
});
1202+
expect(res2.status).toBe(400); // Should fail validation
1203+
1204+
// Protected action should not be in schema
1205+
const res3 = await call(url, {
1206+
query: "{ protectedData }"
1207+
});
1208+
expect(res3.status).toBe(400); // Should fail validation
1209+
1210+
await broker.stop();
1211+
});
1212+
1213+
it("should publish private actions", async () => {
1214+
const { broker, url } = await startService({
1215+
checkActionVisibility: false
1216+
});
1217+
1218+
await broker.createService({
1219+
name: "visibility-test",
1220+
actions: {
1221+
publishedAction: {
1222+
visibility: "published",
1223+
graphql: {
1224+
query: "publishedData: String!"
1225+
},
1226+
handler() {
1227+
return "Published data";
1228+
}
1229+
},
1230+
publicAction: {
1231+
visibility: "public",
1232+
graphql: {
1233+
query: "publicData: String!"
1234+
},
1235+
handler() {
1236+
return "Public data";
1237+
}
1238+
},
1239+
protectedAction: {
1240+
visibility: "protected",
1241+
graphql: {
1242+
query: "protectedData: String!"
1243+
},
1244+
handler() {
1245+
return "Protected data";
1246+
}
1247+
}
1248+
}
1249+
});
1250+
1251+
// Published action should be available
1252+
const res = await call(url, {
1253+
query: "{ publishedData }"
1254+
});
1255+
expect(res.status).toBe(200);
1256+
1257+
// Public action should not be in schema
1258+
const res2 = await call(url, {
1259+
query: "{ publicData }"
1260+
});
1261+
expect(res2.status).toBe(200);
1262+
1263+
// Protected action should not be in schema
1264+
const res3 = await call(url, {
1265+
query: "{ protectedData }"
1266+
});
1267+
expect(res3.status).toBe(200);
1268+
1269+
await broker.stop();
1270+
});
1271+
});
10511272
});

0 commit comments

Comments
 (0)