|
1 | 1 | /* |
2 | | - * Copyright (c) 2022, salesforce.com, inc. |
| 2 | + * Copyright (c) 2025, salesforce.com, inc. |
3 | 3 | * All rights reserved. |
4 | 4 | * SPDX-License-Identifier: BSD-3-Clause |
5 | 5 | * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause |
@@ -224,13 +224,15 @@ describe("oasDiffChangelog", () => { |
224 | 224 | expect(fsStub.writeJson.called).to.be.true; |
225 | 225 | const writtenContent = fsStub.writeJson.args[0][1]; |
226 | 226 | expect(writtenContent).to.be.an("array").with.lengthOf(2); |
227 | | - expect(writtenContent[0]).to.deep.include({ |
228 | | - changes: "in api-v1", |
| 227 | + expect(writtenContent[0]).to.deep.equal({ |
229 | 228 | directory: "api-v1", |
| 229 | + status: "modified", |
| 230 | + changes: { changes: "in api-v1" }, |
230 | 231 | }); |
231 | | - expect(writtenContent[1]).to.deep.include({ |
232 | | - changes: "in api-v2", |
| 232 | + expect(writtenContent[1]).to.deep.equal({ |
233 | 233 | directory: "api-v2", |
| 234 | + status: "modified", |
| 235 | + changes: { changes: "in api-v2" }, |
234 | 236 | }); |
235 | 237 | }); |
236 | 238 |
|
@@ -436,6 +438,94 @@ describe("oasDiffChangelog", () => { |
436 | 438 | expect(writtenContent).to.not.include("=== Changes in stable-api ==="); |
437 | 439 | }); |
438 | 440 |
|
| 441 | + it("should report deleted APIs in JSON format", async () => { |
| 442 | + const execStub = sinon.stub(); |
| 443 | + execStub.callsArgWith(1, null, "version 1.0.0", ""); |
| 444 | + |
| 445 | + const fsStub = { |
| 446 | + readdir: sinon.stub(), |
| 447 | + stat: sinon.stub(), |
| 448 | + writeJson: sinon.stub(), |
| 449 | + }; |
| 450 | + |
| 451 | + // Base has api-v1 and api-v2, new only has api-v2 |
| 452 | + fsStub.readdir.onCall(0).returns(["api-v1", "api-v2"]); // base directories |
| 453 | + fsStub.readdir.onCall(1).returns(["api-v2"]); // new directories |
| 454 | + |
| 455 | + // All stat calls return isDirectory true |
| 456 | + fsStub.stat.returns({ isDirectory: () => true }); |
| 457 | + |
| 458 | + const oasDiff = pq("./oasDiff", { |
| 459 | + child_process: { |
| 460 | + exec: execStub, |
| 461 | + }, |
| 462 | + "fs-extra": fsStub, |
| 463 | + }); |
| 464 | + |
| 465 | + const baseApi = "base"; |
| 466 | + const newApi = "new"; |
| 467 | + const flags = { |
| 468 | + "out-file": "output.json", |
| 469 | + format: "json", |
| 470 | + dir: true, |
| 471 | + }; |
| 472 | + |
| 473 | + await oasDiff.oasDiffChangelog(baseApi, newApi, flags); |
| 474 | + |
| 475 | + expect(fsStub.writeJson.called).to.be.true; |
| 476 | + const writtenContent = fsStub.writeJson.args[0][1]; |
| 477 | + expect(writtenContent).to.be.an("array").with.lengthOf(1); |
| 478 | + expect(writtenContent[0]).to.deep.equal({ |
| 479 | + directory: "api-v1", |
| 480 | + status: "deleted", |
| 481 | + message: "api-v1 API is deleted", |
| 482 | + }); |
| 483 | + }); |
| 484 | + |
| 485 | + it("should report added APIs in JSON format", async () => { |
| 486 | + const execStub = sinon.stub(); |
| 487 | + execStub.callsArgWith(1, null, "version 1.0.0", ""); |
| 488 | + |
| 489 | + const fsStub = { |
| 490 | + readdir: sinon.stub(), |
| 491 | + stat: sinon.stub(), |
| 492 | + writeJson: sinon.stub(), |
| 493 | + }; |
| 494 | + |
| 495 | + // Base has only api-v1, new has api-v1 and api-v2 |
| 496 | + fsStub.readdir.onCall(0).returns(["api-v1"]); // base directories |
| 497 | + fsStub.readdir.onCall(1).returns(["api-v1", "api-v2"]); // new directories |
| 498 | + |
| 499 | + // All stat calls return isDirectory true |
| 500 | + fsStub.stat.returns({ isDirectory: () => true }); |
| 501 | + |
| 502 | + const oasDiff = pq("./oasDiff", { |
| 503 | + child_process: { |
| 504 | + exec: execStub, |
| 505 | + }, |
| 506 | + "fs-extra": fsStub, |
| 507 | + }); |
| 508 | + |
| 509 | + const baseApi = "base"; |
| 510 | + const newApi = "new"; |
| 511 | + const flags = { |
| 512 | + "out-file": "output.json", |
| 513 | + format: "json", |
| 514 | + dir: true, |
| 515 | + }; |
| 516 | + |
| 517 | + await oasDiff.oasDiffChangelog(baseApi, newApi, flags); |
| 518 | + |
| 519 | + expect(fsStub.writeJson.called).to.be.true; |
| 520 | + const writtenContent = fsStub.writeJson.args[0][1]; |
| 521 | + expect(writtenContent).to.be.an("array").with.lengthOf(1); |
| 522 | + expect(writtenContent[0]).to.deep.equal({ |
| 523 | + directory: "api-v2", |
| 524 | + status: "added", |
| 525 | + message: "api-v2 API is added", |
| 526 | + }); |
| 527 | + }); |
| 528 | + |
439 | 529 | it("should throw an error if oasdiff is not installed", async () => { |
440 | 530 | const execStub = sinon.stub(); |
441 | 531 | execStub.callsArgWith(1, new Error("oasdiff not installed")); |
|
0 commit comments