Skip to content

Commit

Permalink
refactor: shorten
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeVanti committed Jul 3, 2024
1 parent 2128392 commit 1c4ff4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
23 changes: 8 additions & 15 deletions src/services/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,15 @@ export function makeLogin(
}

// npm login
return npmLogin(registry, username, password, email).andThen((token) => {
return npmLogin(registry, username, password, email).map(async (token) => {
debugLog(`npm login successful`);
// write npm token
return resultifyAsyncOp(authNpmrc(registry, token)).andThen(
(npmrcPath) => {
debugLog(`saved to npm config: ${npmrcPath}`);
// Save config
return resultifyAsyncOp(
saveAuthToUpmConfig(configPath, registry, {
email,
alwaysAuth,
token,
} satisfies TokenAuth)
);
}
);
const npmrcPath = await authNpmrc(registry, token);
debugLog(`saved to npm config: ${npmrcPath}`);
await saveAuthToUpmConfig(configPath, registry, {
email,
alwaysAuth,
token,
} satisfies TokenAuth);
});
};
}
18 changes: 0 additions & 18 deletions test/services/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,5 @@ describe("login", () => {
}
);
});

it("should fail if config write fails", async () => {
const expected = new GenericIOError("Write");
const { login, saveAuthToUpmConfig } = makeDependencies();
saveAuthToUpmConfig.mockRejectedValue(expected);

const result = await login(
exampleUser,
examplePassword,
exampleEmail,
true,
exampleRegistryUrl,
exampleConfigPath,
"token"
).promise;

expect(result).toBeError((actual) => expect(actual).toEqual(expected));
});
});
});

0 comments on commit 1c4ff4e

Please sign in to comment.