-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor on the SDK #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| "gitignoreio-sdk": minor | ||
| --- | ||
|
|
||
| Change the `generate` return type to a Promise. | ||
| With this change the user of the SDK do not have to know or use `neverthrow`. | ||
| It is enough to properly handle the Promise instead. | ||
|
|
||
| > [!NOTE] | ||
| > Even though this would be a major update since the contract has changed, | ||
| > I decided to bump a minor instead, following the [SemVer specification](https://semver.org) | ||
| > which allows to change the contract when the major is under `1`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { mock } from 'vitest-mock-extended'; | ||
|
|
||
| import type { HttpClient } from '../domain'; | ||
| import type { HttpClient } from '../domain/http-client'; | ||
|
|
||
| export const makeMockHttpClient = () => mock<HttpClient>(); |
25 changes: 0 additions & 25 deletions
25
packages/gitignoreio-sdk/src/__tests__/gitignore-sdk.test.ts
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
packages/gitignoreio-sdk/src/adapters/__tests__/sdk.tests.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { errAsync, okAsync } from 'neverthrow'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { makeMockHttpClient } from '../../__tests__/data.js'; | ||
| import { GitIgnoreSDK } from '../sdk'; | ||
|
|
||
| describe('GitIgnoreSDK', () => { | ||
| describe('generate', () => { | ||
| it('should return the .gitignore content', async () => { | ||
| const mockContent = '# Node.js\nnode_modules/\nnpm-debug.log'; | ||
| const mockHttpClient = makeMockHttpClient(); | ||
| mockHttpClient.get.mockReturnValueOnce(okAsync(mockContent)); | ||
| const sdk = new GitIgnoreSDK(mockHttpClient); | ||
|
|
||
| const result = await sdk.generate(['node', 'python']); | ||
|
|
||
| expect(mockHttpClient.get).toHaveBeenCalledWith( | ||
| new URL( | ||
| 'https://www.toptal.com/developers/gitignore/api/node%2Cpython', | ||
| ), | ||
| ); | ||
| expect(result).toStrictEqual({ content: mockContent }); | ||
| }); | ||
|
|
||
| it('should throw an error when HTTP client fails', async () => { | ||
| const mockHttpClient = makeMockHttpClient(); | ||
| mockHttpClient.get.mockReturnValueOnce(errAsync(new Error('anError'))); | ||
| const sdk = new GitIgnoreSDK(mockHttpClient); | ||
|
|
||
| await expect(sdk.generate(['node', 'python'])).rejects.toStrictEqual( | ||
| new Error('There was an error fetching data from gitignore.io'), | ||
| ); | ||
|
|
||
| expect(mockHttpClient.get).toHaveBeenCalledWith( | ||
| new URL( | ||
| 'https://www.toptal.com/developers/gitignore/api/node%2Cpython', | ||
| ), | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import type { ResultAsync } from 'neverthrow'; | ||
|
|
||
| /** | ||
| * Interface for HTTP client dependency. | ||
| */ | ||
| export interface HttpClient { | ||
| get(url: URL): ResultAsync<string, Error>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletion
8
...oreio-sdk/src/domain/gitignore-element.ts → .../gitignoreio-sdk/src/domain/technology.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,10 @@ | ||||||
| export type GitIgnoreElement = | ||||||
| /** | ||||||
| * Input for generating gitignore content. | ||||||
| * A non-empty array of technology names. | ||||||
| */ | ||||||
| export type Technologies = [Technology, ...Technology[]]; | ||||||
|
|
||||||
| type Technology = | ||||||
|
||||||
| type Technology = | |
| export type Technology = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| export { GitIgnoreSDK } from './gitignore-sdk.js'; | ||
| export { GitIgnoreSDK } from './adapters/sdk'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling discards the original error information. The match function receives an error parameter that should be used to provide more meaningful error messages or at least preserve the original error context.