-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: login twitter service * fix: add path alias * fix: description text test fixed * feat: implements poo and Unauthorized error * fix: code style fixed * feat: change GenerateAuthURL function for class * chore: add constructor in login twitter service * fix: path alias * fix: adjust error in test
- Loading branch information
Showing
8 changed files
with
143 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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 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 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,19 @@ | ||
import { GenerateAuthURL } from './generate-auth-url'; | ||
|
||
describe('GenerateAuthUrl', () => { | ||
let sut: GenerateAuthURL; | ||
let id: string; | ||
|
||
beforeEach(() => { | ||
sut = new GenerateAuthURL(); | ||
id = '1'; | ||
}); | ||
|
||
it('should return the generated twitter auth URL', () => { | ||
const url = sut.twitter({ id }); | ||
|
||
expect(url).toBe( | ||
`https://twitter.com/i/oauth2/authorize?client_id=undefined&code_challenge=-a4-ROPIVaUBVj1qqB2O6eN_qSC0WvET0EdUEhSFqrI&code_challenge_method=S256&redirect_uri=http%3A%2F%2Fwww.localhost%3A3000%2Fapi%2Ftwitter%2Fcallback&response_type=code&state=${id}&scope=tweet.write%20tweet.read%20users.read` | ||
); | ||
}); | ||
}); |
This file contains 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
20 changes: 20 additions & 0 deletions
20
src/features/twitter/services/login-twitter-service.test.ts
This file contains 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,20 @@ | ||
import { GenerateAuthURL } from '../helpers/generate-auth-url'; | ||
import { LoginTwitterService } from './login-twitter-service'; | ||
|
||
describe('LoginTwitterService', () => { | ||
let sut: LoginTwitterService; | ||
let generateAuthUrl: GenerateAuthURL; | ||
let id: string; | ||
|
||
beforeEach(() => { | ||
generateAuthUrl = new GenerateAuthURL(); | ||
sut = new LoginTwitterService(generateAuthUrl); | ||
id = '1'; | ||
}); | ||
|
||
it('should return the generated auth URL', () => { | ||
const result = sut.execute({ userId: id }); | ||
|
||
expect(result).toContain('https://twitter.com/i/oauth2/authorize'); | ||
}); | ||
}); |
This file contains 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,17 @@ | ||
import type { Service } from '@/shared/protocols/service'; | ||
|
||
import type { GenerateAuthURL } from '../helpers/generate-auth-url'; | ||
|
||
type Input = { | ||
userId: string; | ||
}; | ||
|
||
export class LoginTwitterService implements Service<Input, string> { | ||
constructor(private readonly generateAuthUrl: GenerateAuthURL) {} | ||
|
||
execute({ userId }: Input) { | ||
const url = this.generateAuthUrl.twitter({ id: userId }); | ||
|
||
return url; | ||
} | ||
} |
This file contains 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 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,15 @@ | ||
import { HttpError } from '@/shared/errors/http-error'; | ||
import { HttpStatusCode } from '@/shared/protocols/http-client'; | ||
|
||
export class UnauthorizedHeaderError extends HttpError { | ||
constructor(public readonly message: string = 'Unauthorized') { | ||
super(HttpStatusCode.unauthorized, message); | ||
} | ||
|
||
public toJSON() { | ||
return { | ||
code: this.code, | ||
error: this.message, | ||
}; | ||
} | ||
} |