Skip to content

Commit

Permalink
test: idempotent test
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Dec 31, 2023
1 parent d4f1bf4 commit a5e4df7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/credential.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,23 @@ describe('credential', () => {
expect(restoredRemoteUrl).toBe(originalRemoteUrl);
expect(restoredRemoteUrl.includes(exampleToken)).toBe(false);
});

test('methods are idempotent', async () => {
const originalRemoteUrl = await getRemoteUrl(dir, defaultGitInfo.remote);
await credentialOn(dir, originalRemoteUrl, defaultGitInfo.gitUserName, exampleToken, defaultGitInfo.remote);
const newRemoteUrl1 = await getRemoteUrl(dir, defaultGitInfo.remote);
expect(newRemoteUrl1.includes(exampleToken)).toBe(true);
await credentialOn(dir, newRemoteUrl1, defaultGitInfo.gitUserName, exampleToken, defaultGitInfo.remote);
await credentialOn(dir, newRemoteUrl1, defaultGitInfo.gitUserName, exampleToken, defaultGitInfo.remote);
await credentialOn(dir, newRemoteUrl1, defaultGitInfo.gitUserName, exampleToken, defaultGitInfo.remote);
const newRemoteUrl2 = await getRemoteUrl(dir, defaultGitInfo.remote);
expect(newRemoteUrl2.includes(exampleToken)).toBe(true);
expect(newRemoteUrl2).toBe(newRemoteUrl1);
await credentialOff(dir, defaultGitInfo.remote);
await credentialOff(dir, defaultGitInfo.remote);
await credentialOff(dir, defaultGitInfo.remote);
const restoredRemoteUrl = await getRemoteUrl(dir, defaultGitInfo.remote);
expect(restoredRemoteUrl).toBe(originalRemoteUrl);
expect(restoredRemoteUrl.includes(exampleToken)).toBe(false);
});
});

0 comments on commit a5e4df7

Please sign in to comment.