Skip to content

Commit 2e7185c

Browse files
committed
Fix unit tests.
1 parent a6101dd commit 2e7185c

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

src/init/features/dataconnect/schema.spec.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("addSchemaToDataConnectYaml", () => {
2121
beforeEach(() => {
2222
dataConnectYaml = {
2323
location: "us-central1",
24-
serviceId: "test-service",
24+
serviceId: "service-id",
2525
connectorDirs: [],
2626
};
2727
schemaRequiredInfo = {
@@ -68,7 +68,7 @@ describe("addSchemaToDataConnectYaml", () => {
6868
];
6969
addSchemaToDataConnectYaml(dataConnectYaml, schemaRequiredInfo);
7070
expect(dataConnectYaml.schema).to.be.undefined;
71-
expect(dataConnectYaml.schemas).to.have.lengthOf(2);
71+
expect(dataConnectYaml.schemas).to.have.lengthOf(3);
7272
expect(dataConnectYaml.schemas).to.deep.equal([
7373
{
7474
source: "./schema",
@@ -117,7 +117,7 @@ describe("askQuestions", () => {
117117
});
118118

119119
it("should throw error when fdcwebhooks experiment is not enabled", async () => {
120-
experimentsStub.resolves(false);
120+
experimentsStub.returns(false);
121121

122122
try {
123123
await askQuestions(setup, config);
@@ -127,7 +127,7 @@ describe("askQuestions", () => {
127127
});
128128

129129
it("should throw error when no services", async () => {
130-
experimentsStub.resolves(true);
130+
experimentsStub.returns(true);
131131
loadAllStub.resolves([]);
132132

133133
try {
@@ -142,8 +142,13 @@ describe("askQuestions", () => {
142142
});
143143

144144
it("should skip service selection when exactly one service", async () => {
145-
experimentsStub.resolves(true);
146-
loadAllStub.resolves([{ serviceName: "service-name" }]);
145+
experimentsStub.returns(true);
146+
loadAllStub.resolves([
147+
{
148+
serviceName: "projects/project-id/locations/us-central1/services/service-id",
149+
dataConnectYaml: { location: "us-central1", serviceId: "service-id" },
150+
},
151+
]);
147152
inputStub.onFirstCall().resolves("test_resolver");
148153
inputStub.onSecondCall().resolves("www.test.com");
149154

@@ -153,16 +158,24 @@ describe("askQuestions", () => {
153158
expect(inputStub.calledTwice).to.be.true;
154159
expect(setup.featureInfo?.dataconnectSchema?.id).to.equal("test_resolver");
155160
expect(setup.featureInfo?.dataconnectSchema?.uri).to.equal("www.test.com");
156-
expect(setup.featureInfo?.dataconnectSchema?.serviceInfo.serviceName).to.equal("service-name");
161+
expect(setup.featureInfo?.dataconnectSchema?.serviceInfo.serviceName).to.equal(
162+
"projects/project-id/locations/us-central1/services/service-id",
163+
);
157164
});
158165

159166
it("should prompt for service selection when multiple services", async () => {
160-
experimentsStub.resolves(true);
167+
experimentsStub.returns(true);
161168
loadAllStub.resolves([
162-
{ serviceName: "service-name" },
163-
{ serviceName: "another-service-name" },
169+
{ serviceName: "projects/project-id/locations/us-central1/services/service-id" },
170+
{
171+
serviceName: "projects/project-id/locations/us-central1/services/service-id2",
172+
dataConnectYaml: { location: "us-central1", serviceId: "service-id2" },
173+
},
164174
]);
165-
selectStub.resolves({ serviceName: "another-service-name" });
175+
selectStub.resolves({
176+
serviceName: "projects/project-id/locations/us-central1/services/service-id2",
177+
dataConnectYaml: { location: "us-central1", serviceId: "service-id2" },
178+
});
166179
inputStub.onFirstCall().resolves("test_resolver");
167180
inputStub.onSecondCall().resolves("www.test.com");
168181

@@ -173,7 +186,7 @@ describe("askQuestions", () => {
173186
expect(setup.featureInfo?.dataconnectSchema?.id).to.equal("test_resolver");
174187
expect(setup.featureInfo?.dataconnectSchema?.uri).to.equal("www.test.com");
175188
expect(setup.featureInfo?.dataconnectSchema?.serviceInfo.serviceName).to.equal(
176-
"another-service-name",
189+
"projects/project-id/locations/us-central1/services/service-id2",
177190
);
178191
});
179192
});
@@ -199,11 +212,11 @@ describe("actuate", () => {
199212
uri: "www.test.com",
200213
serviceInfo: {
201214
sourceDirectory: "/path/to/service",
202-
serviceName: "test-service",
215+
serviceName: "service-id",
203216
schemas: [],
204217
dataConnectYaml: {
205218
location: "us-central1",
206-
serviceId: "test-service",
219+
serviceId: "service-id",
207220
schemas: [
208221
{
209222
source: "./schema",
@@ -238,7 +251,7 @@ describe("actuate", () => {
238251
});
239252

240253
it("should no-op when fdcwebhooks experiment is not enabled", async () => {
241-
experimentsStub.resolves(false);
254+
experimentsStub.returns(false);
242255

243256
await actuate(setup, config);
244257

@@ -247,15 +260,15 @@ describe("actuate", () => {
247260
});
248261

249262
it("should write dataconnect.yaml and set up empty secondary schema file", async () => {
250-
experimentsStub.resolves(true);
263+
experimentsStub.returns(true);
251264

252265
await actuate(setup, config);
253266

254267
expect(writeProjectFileStub.calledOnce).to.be.true;
255268
const writtenYamlPath = writeProjectFileStub.getCall(0).args[0];
256269
const writtenYamlContents = writeProjectFileStub.getCall(0).args[1];
257270
const parsedYaml = yaml.load(writtenYamlContents);
258-
expect(writtenYamlPath).to.equal("/path/to/service/dataconnect.yaml");
271+
expect(writtenYamlPath).to.equal("../service/dataconnect.yaml");
259272
expect(parsedYaml.schemas).to.have.lengthOf(2);
260273
expect(ensureSyncStub.calledOnce).to.be.true;
261274
const writtenSchemaPath = ensureSyncStub.getCall(0).args[0];

0 commit comments

Comments
 (0)