-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move comment form ajax post into resource
- Pull axios out of the DonationCommentPopUp component and wraps it in a resource. - Add tests for post response handling Ticket: https://phabricator.wikimedia.org/T367387
- Loading branch information
Showing
6 changed files
with
126 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import axios, { AxiosResponse } from 'axios'; | ||
|
||
export interface CommentRequest { | ||
donationId: number; | ||
updateToken: string; | ||
comment: string; | ||
withName: boolean; | ||
isPublic: boolean; | ||
} | ||
|
||
interface CommentResponse { | ||
status: string; | ||
message: string; | ||
} | ||
|
||
export interface CommentResource { | ||
post: ( data: CommentRequest ) => Promise<string>; | ||
} | ||
|
||
export class ApiCommentResource implements CommentResource { | ||
postEndpoint: string; | ||
|
||
constructor( postEndpoint: string ) { | ||
this.postEndpoint = postEndpoint; | ||
} | ||
|
||
post( data: CommentRequest ): Promise<string> { | ||
return axios.post( this.postEndpoint, data ).then( ( validationResult: AxiosResponse<CommentResponse> ) => { | ||
if ( validationResult.data.status === 'OK' ) { | ||
return Promise.reject(); | ||
} | ||
return validationResult.data.message; | ||
} ); | ||
} | ||
} |
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,15 @@ | ||
import { CommentResource } from '@src/api/CommentResource'; | ||
|
||
export const successMessage = 'Success'; | ||
|
||
export class FakeSucceedingCommentResource implements CommentResource { | ||
post(): Promise<string> { | ||
return Promise.resolve( successMessage ); | ||
} | ||
} | ||
|
||
export class FakeFailingCommentResource implements CommentResource { | ||
post(): Promise<string> { | ||
return Promise.reject(); | ||
} | ||
} |
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