-
Notifications
You must be signed in to change notification settings - Fork 275
Stephen's frontend-api-challenge #125
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
Open
stephenfletchtek
wants to merge
26
commits into
makersacademy:master
Choose a base branch
from
stephenfletchtek:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
95a3455
project set up
stephenfletchtek 5b7894c
first test passed
stephenfletchtek 8dbf2b0
implement and test drive PeepsModel
stephenfletchtek 9f02184
jest environment jsdom added and peepsView skeleton created
stephenfletchtek 5bddb50
test drive ChitterApi loadPeeps method
stephenfletchtek 0716c8b
display peeps tested
stephenfletchtek f1d5b51
displayClear method test driven
stephenfletchtek a76ae35
test drive displayFromApi method
stephenfletchtek bfa7b95
test drive elapsed days and display handle and days about peep
stephenfletchtek cd8c275
test drive api createUser method
stephenfletchtek 95570c4
submit button works but not capturing text input
stephenfletchtek cd97e3d
passes with text element values assigned in class
stephenfletchtek a9cf1a7
cannot get input values from jest test into class
stephenfletchtek b85eebc
add user test passes with nasty workaround
stephenfletchtek 7ae6e52
test passed at last!
stephenfletchtek eb87919
test passed
stephenfletchtek 05f5c97
api.loadSession methdod test driven
stephenfletchtek b8d59f1
log in works with fake response - need to implement response
stephenfletchtek 515c5f3
test drive login success
stephenfletchtek f90930f
fixed run build issue
stephenfletchtek 35b35c8
re set
stephenfletchtek 86600d3
fix session api typo - can now log in!
stephenfletchtek ef70ebb
basic login
stephenfletchtek 7e183a5
api postPeep test driven
stephenfletchtek 65b1777
sign up, sign in and post a peep but layout is a mess
stephenfletchtek 9c6bfb8
moved text input and submit to post a peep to the top of the page
stephenfletchtek 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
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,3 @@ | ||
node_modules/ | ||
bundle.js | ||
user.json |
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,48 @@ | ||
class ChitterApi { | ||
|
||
loadPeeps(callback) { | ||
const callbackFn = callback || (() => { }) | ||
fetch('https://chitter-backend-api-v2.herokuapp.com/peeps') | ||
.then(response => response.json()) | ||
.then((data) => callbackFn(data)); | ||
} | ||
|
||
createUser(user, callback) { | ||
const callbackFn = callback || (() => { }) | ||
fetch('https://chitter-backend-api-v2.herokuapp.com/users', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(user) | ||
}) | ||
.then(response => response.json()) | ||
.then(data => callbackFn(data)); | ||
} | ||
|
||
loadSession(session, callback) { | ||
const callbackFn = callback || (() => { }) | ||
fetch('https://chitter-backend-api-v2.herokuapp.com/sessions', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(session) | ||
}) | ||
.then(response => response.json()) | ||
.then(data => callbackFn(data)); | ||
} | ||
|
||
postPeep(token, peep, callback) { | ||
const callbackFn = callback || (() => { }) | ||
fetch('https://chitter-backend-api-v2.herokuapp.com/peeps', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': 'Token token=' + token | ||
}, | ||
body: JSON.stringify(peep) | ||
}) | ||
.then(response => response.json()) | ||
.then(data => callbackFn(data)); | ||
} | ||
|
||
} | ||
|
||
module.exports = ChitterApi; |
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,44 @@ | ||
require('jest-fetch-mock').enableMocks(); | ||
const ChitterApi = require('./chitterApi'); | ||
|
||
describe('ChitterApi class', () => { | ||
beforeEach(() => { | ||
api = new ChitterApi; | ||
}) | ||
|
||
it('views all peeps', () => { | ||
expect.assertions(1); | ||
fetch.mockResponseOnce(JSON.stringify({ body: 'my first peep' })) | ||
api.loadPeeps((data) => { | ||
expect(data.body).toBe('my first peep'); | ||
}) | ||
}) | ||
|
||
it('creates a user', () => { | ||
expect.assertions(2); | ||
fetch.mockResponseOnce(JSON.stringify({ id: 1, handle: "user" })); | ||
api.createUser({ user: { handle: "user", password: "secret" } }, (response) => { | ||
expect(response.id).toEqual(1); | ||
expect(response.handle).toEqual('user'); | ||
}) | ||
}) | ||
|
||
it('creates a session', () => { | ||
expect.assertions(2); | ||
fetch.mockResponseOnce(JSON.stringify({ user_id: 1, session_key: "stuff" })); | ||
const session = { session: { handle: "test", password: "test" } } | ||
api.loadSession(session, (response) => { | ||
expect(response.user_id).toEqual(1); | ||
expect(response.session_key).toEqual("stuff"); | ||
}) | ||
}) | ||
|
||
it('creates a peep', () => { | ||
expect.assertions(1); | ||
fetch.mockResponseOnce(JSON.stringify({ body: 'quack!' })); | ||
api.postPeep('fake', 'whassup?', (response) => { | ||
expect(response.body).toEqual('quack!'); | ||
}) | ||
}) | ||
|
||
}) |
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,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<script type="text/javascript" src="bundle.js" defer></script> | ||
|
||
<title>Chitter</title> | ||
</head> | ||
|
||
<body> | ||
<h1>Chitter</h1> | ||
<div id="main-container"> | ||
<div id="user"> | ||
<button id="post">Post Peep</button> | ||
<button id="sign-up">Sign Up</button> | ||
<button id="sign-in">Sign In</button> | ||
</div> | ||
<div id="post-peep"></div> | ||
|
||
</div> | ||
</body> | ||
|
||
</html> |
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,11 @@ | ||
const PeepsModel = require('./peepsModel') | ||
const ChitterApi = require('./chitterApi'); | ||
const PeepsView = require('./peepsView'); | ||
|
||
const model = new PeepsModel; | ||
const api = new ChitterApi; | ||
const peepsView = new PeepsView(model, api); | ||
|
||
console.log('Chitter is running'); | ||
|
||
peepsView.displayFromApi(); |
Oops, something went wrong.
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.
You reference this a lot - not sure why you have it but you could make it a line in the constructor eg.
this.callbackFn()
instead of writing it every time