"use strict";

jest.mock("pacote");

// mocked module(s)
const pacote = require("pacote");

// helpers
const { PackageGraph } = require("@lerna/package-graph");
const { getPackages } = require("@lerna/project");
const initFixture = require("@lerna-test/init-fixture")(__dirname);

// file under test
const { getUnpublishedPackages } = require("../lib/get-unpublished-packages");

pacote.packument.mockImplementation(async (pkg) => {
  if (pkg === "package-1") {
    return {
      versions: {},
    };
  }

  if (pkg === "package-2") {
    return {
      versions: {
        "1.0.0": {},
      },
    };
  }

  throw new Error("package does not exist");
});

test("getUnpublishedPackages", async () => {
  const cwd = await initFixture("licenses-names");
  const packages = await getPackages(cwd);
  const packageGraph = new PackageGraph(packages);

  const opts = new Map();
  const pkgs = await getUnpublishedPackages(packageGraph, opts);

  expect(pkgs).toMatchInlineSnapshot(`
Array [
  PackageGraphNode {
    "externalDependencies": Map {},
    "localDependencies": Map {},
    "localDependents": Map {},
    "name": "package-1",
  },
  PackageGraphNode {
    "externalDependencies": Map {},
    "localDependencies": Map {},
    "localDependents": Map {},
    "name": "package-3",
  },
  PackageGraphNode {
    "externalDependencies": Map {},
    "localDependencies": Map {},
    "localDependents": Map {},
    "name": "package-4",
  },
  PackageGraphNode {
    "externalDependencies": Map {},
    "localDependencies": Map {},
    "localDependents": Map {},
    "name": "package-5",
  },
]
`);
});

test("getUnpublishedPackages with private package", async () => {
  const cwd = await initFixture("public-private");
  const packages = await getPackages(cwd);
  const packageGraph = new PackageGraph(packages);

  const opts = new Map();
  const pkgs = await getUnpublishedPackages(packageGraph, opts);

  expect(pkgs).toMatchInlineSnapshot(`
Array [
  PackageGraphNode {
    "externalDependencies": Map {},
    "localDependencies": Map {},
    "localDependents": Map {},
    "name": "package-1",
  },
]
`);
});

@@ -854,33 +854,26 @@
 onst opts = 
-new Map()
+%7B%7D
 ;%0A  const pk
@@ -920,32 +920,100 @@
 eGraph, opts);%0A%0A
+  expect(pacote.packument).toHaveBeenCalledWith(%22package-1%22, opts);%0A
   expect(pkgs).t
@@ -1889,17 +1889,10 @@
 s = 
-new Map()
+%7B%7D
 ;%0A  
@@ -1947,32 +1947,100 @@
 eGraph, opts);%0A%0A
+  expect(pacote.packument).toHaveBeenCalledWith(%22package-1%22, opts);%0A
   expect(pkgs).t

Update lib tests with correct options