These are chat archives for FreeCodeCamp/HelpJavaScript

26th
Dec 2018
tundeiness
@tundeiness
Dec 26 2018 06:47
@cmccormack great!!! thanks.
enestatli
@enestatli
Dec 26 2018 09:24

@tiagocorreiaalmeida Take a look at this: https://github.com/karan/Projects#web

@matrixersp thanks a lot!

Mohammed Boudad
@matrixersp
Dec 26 2018 09:25
@enestatli No worries
Idowu Wasiu
@Hoxtygen
Dec 26 2018 11:21
good day guys
anyone here use postgresql?
should there be anyone using it online now or later here
Here's my problem... It's really runnin fine, but I'm not convinced about the testing using mocha and chai
alpox
@alpox
Dec 26 2018 11:26
@Hoxtygen what did you plan to test / and how?
Idowu Wasiu
@Hoxtygen
Dec 26 2018 11:26
@alpox my api endpoints
alpox
@alpox
Dec 26 2018 11:26
@Hoxtygen unit test or integration?
Idowu Wasiu
@Hoxtygen
Dec 26 2018 11:27
@alpox integration testing
Here's my setup
import chai from 'chai';
import chaiHttp from 'chai-http';
import { describe } from 'mocha';
import app from '../server';
import dbConfig from '../database/dbConfig';


chai.use(chaiHttp);
chai.should();

describe('Books. Showing that the books api is working properly', () => {
  describe('Get all books from the database', () => {
    it('should get all books from the database', (done) => {
      chai.request(app);
      dbConfig.query('SELECT * FROM book_library.books')
        .then((err, res) => {
          console.log(res);
          res.should.have.status(200);
          res.body.should.be.a('object');
        });
      done();
    });
  });

  describe('Get a single book from the database', () => {
    it('should get a single book from the database', (done) => {
      chai.request(app);
      const book_id = 6;
      dbConfig.query(`SELECT * FROM book_library.books WHERE book_id = ${book_id}`)
        .then((err, res) => {
          res.should.have.status(200);
          res.body.should.be.a('object');
        });
      done();
    });
  });
});
alpox
@alpox
Dec 26 2018 11:28
@Hoxtygen you have 2 options. 1. You create a test database which you switch in/out depending on the environment and use the test database while testing
  1. You wrap all your tests into database transactions which you never commit but rollback after every test (transactions can be nested)
That was 2.
Idowu Wasiu
@Hoxtygen
Dec 26 2018 11:29
@alpox hold on please, I'm new to this
@alpox Can you check the code I pasted and help from there?
Actually, those tests I wrote are passing. However, when getting a single book and i change the boo_id to 100 or another number not in the database it still passes. that shouldn't pass
alpox
@alpox
Dec 26 2018 11:32
Hmm I will comment some things
You say you want to test your API endpoints with integration tests. Now I see you make direct database requests in your tests. This doesnt line ip
If you want to test the API you have to talk to the api. At the moment you are merely testing if the database driver works which is not the scope of your code really
The reason your tests all pass so or so is that you put the done() callback outside the database callback which makes mocha think that the test is done when its not yet. The test is closed and asserted as ok before the database answers.
You interpolate the id through string interpolation to create the sql you want. You have to get used to NEVER DO THAT (you open the door to one of the main security issues - SQL injection)
@Hoxtygen that are my main points for now :)
Idowu Wasiu
@Hoxtygen
Dec 26 2018 11:38
@alpox Thanks for your observation.
@alpox Now how do I solve these issues. Like I said, I'm new to this..... tutorials on postgresql and nodejs testing are scarce
@alpox any help will be appreciated
alpox
@alpox
Dec 26 2018 11:41
@Hoxtygen im not sure what code there is in your app already. There should not be any database queries in your test code when you want to write API tests anyway.
So you should only ask something like: does the endpoint /book/6 give me the right book number 6 if it exists in the database?
Idowu Wasiu
@Hoxtygen
Dec 26 2018 11:43
@alpox if you dont mind here's the repo https://github.com/Hoxtygen/library and it's up to date
alpox
@alpox
Dec 26 2018 11:43
@Hoxtygen i see you do have the api code. So you should directly talk to the server and not to the database
Idowu Wasiu
@Hoxtygen
Dec 26 2018 11:44
@alpox Was thinking like that, just that my implementation was wrong
alpox
@alpox
Dec 26 2018 11:44
The api server will invoke the right code to get the book from the database
The implementation of the api, p
?
Idowu Wasiu
@Hoxtygen
Dec 26 2018 11:45
So you should only ask something like: does the endpoint /book/6 give me the right book number 6 if it exists in the database?
was responding to this
@alpox I actually got everything working using postman, just want to write the integration testing tooo
alpox
@alpox
Dec 26 2018 11:46

Hmm damn this doesnt work well on phone :D
chai.request('http://localhost:8080')
.get('/')
.end(function(err, res) {
expect(res).to.have.status(123);
done(); // <= Call done to signal callback end
});
Test code would look about like this
Except that you use the .should interface of chai as I saw
Sorry for the missing formatting - it was not possible to put it right on mobile
Idowu Wasiu
@Hoxtygen
Dec 26 2018 11:48
I can always import the expect(), that shouldn't be a problem
alpox
@alpox
Dec 26 2018 11:49
Well its not a problem to use should instead either
Idowu Wasiu
@Hoxtygen
Dec 26 2018 11:49
Sorry for the missing formatting - it was not possible to put it right on mobile
not sure someone in need of help should cherry pick. I can read that perfectly
alpox
@alpox
Dec 26 2018 11:50
@Hoxtygen best would be to refer to the proper documentation
The code i posted you is from there too
Idowu Wasiu
@Hoxtygen
Dec 26 2018 11:52
@alpox damn me, I have chai should/expect and chai assert open here...been reading with no luck. Never thought about reading the plugins.... Thanks man
alpox
@alpox
Dec 26 2018 11:52
@Hoxtygen :D
No problem
Finding the right docs is half the work :D
Idowu Wasiu
@Hoxtygen
Dec 26 2018 11:54
@alpox will hit you up if I run into issues again... gotta get busy.... Thanks again man.
alpox
@alpox
Dec 26 2018 11:55
@Hoxtygen also take a look atthe pg docs
And update your queries to use prepared parameters instead of string interpolation
With the way your current queries are written I could easily wipe out your database or even more just by talking a bit with your api
Idowu Wasiu
@Hoxtygen
Dec 26 2018 11:58
@alpox oh okay....,
@alpox I thought something like this is supposed to protect againt sql injection

 dbConfig.query('INSERT INTO book_library.books (title, pubyear, publisher, author_id, category_id, image_url) VALUES ($1, $2, $3, $4, $5, $6)
alpox
@alpox
Dec 26 2018 12:01
@Hoxtygen yes this is
WHERE book_id = ${book_id} but this will bite your ass
Idowu Wasiu
@Hoxtygen
Dec 26 2018 12:02
@alpox It's what I used when making a post request
alpox
@alpox
Dec 26 2018 12:02
Same for GET requests though
I can wipe your database with a get request as well :)
Idowu Wasiu
@Hoxtygen
Dec 26 2018 12:03
@alpox Oh wait, I can use same for get requests? didnt know that
alpox
@alpox
Dec 26 2018 12:03
Yes, they show it in the docs
Idowu Wasiu
@Hoxtygen
Dec 26 2018 12:04
@alpox I am self studying, just learning what I could so I can get a job
@alpox good to have talked to you.....
alpox
@alpox
Dec 26 2018 12:05
@Hoxtygen sure, no need to explain :) this is a place of self-learners like you. We are here to help with these things and tell you when something is not good yet so you can learn :)
Idowu Wasiu
@Hoxtygen
Dec 26 2018 12:06
@alpox funny how this is always my last place of soujourn when all stops working or not working at all..... I guess that have to change
alpox
@alpox
Dec 26 2018 12:08
@Hoxtygen well these chats are not so active anymore. Most people are in the forums now or the discord chat
Idowu Wasiu
@Hoxtygen
Dec 26 2018 12:10
I used to be active here, got super busy and hardly visit anymore except when I run into trouble like today.... Didnt know about the discord chat.... got a link?
It is an unofficial chat though
But I think it already has more members than gitter
I am not active there
Idowu Wasiu
@Hoxtygen
Dec 26 2018 12:12
who cares? so much I can get help from there @alpox
@alpox will be running the two to get help..... My experience here is good.. Lots of people always trying to help
alpox
@alpox
Dec 26 2018 12:13
@Hoxtygen i hope you do :) to me that discord chat looked always more like blabla around than actually helping/improving
Idowu Wasiu
@Hoxtygen
Dec 26 2018 12:15
@alpox oh well, here would be better then. I like how our communication didnt get interrupted by others. Else I'd have been looking through a pile of chats to get your response
alpox
@alpox
Dec 26 2018 12:16
Yes its better to focus :)
Idowu Wasiu
@Hoxtygen
Dec 26 2018 12:22
@alpox and do you think the project is worth anything? looking from the perspective of someone trying to hire? like would you consider that something?
Idowu Wasiu
@Hoxtygen
Dec 26 2018 12:28
@alpox hi, just followed the docs and one of my test just passed... thanks for pointing me to the right direction.....
alpox
@alpox
Dec 26 2018 13:51
@Hoxtygen youre welcome :)
I did not look through it that closely. I believe it would be fine for an internship to junior position
enestatli
@enestatli
Dec 26 2018 13:56
junior? Oh God helps me :D
Jason Luboff
@JLuboff
Dec 26 2018 16:07
Morning :wave:
alpox
@alpox
Dec 26 2018 16:15
@JLuboff hio :) how is it going?
Jason Luboff
@JLuboff
Dec 26 2018 16:20
@alpox Not too bad... had a nice four day weekend and back to work now, yourself?
alpox
@alpox
Dec 26 2018 16:20
@JLuboff was nice but a bit much to do as I come back to switzerland now after 3 months in prag. Lots of apartment cleaning and packing next to christmas with the family of my gf :)
Jason Luboff
@JLuboff
Dec 26 2018 16:21
You've already been in prague for 3 months? Man..time flies hah
alpox
@alpox
Dec 26 2018 16:22
@JLuboff poor you, have to work already! I have free until after new years :)
@JLuboff yea time is going pretty fast thats true
Jason Luboff
@JLuboff
Dec 26 2018 16:22
Ya.... but atleast this week is only 3 days and next week only 4 days
alpox
@alpox
Dec 26 2018 16:23
Good, thats more chilly :) hopefully you have no stressful work either
Jason Luboff
@JLuboff
Dec 26 2018 16:23
Should be fairly relaxed.. just focus on coding
alpox
@alpox
Dec 26 2018 16:23
Nice, thats what we programmers like, isnt it :D
Jason Luboff
@JLuboff
Dec 26 2018 16:23
Indeed it is haha
I hope to get Scheme setup this week too so I can do the practice/examples from SICP
alpox
@alpox
Dec 26 2018 16:26
Ah nice yes :D
If you have WSL you can just run sudo apt-get install mit-scheme
Jason Luboff
@JLuboff
Dec 26 2018 16:28
Just tried it, says unable to locate the package :( (through WSL with Ubuntu as the distro)
alpox
@alpox
Dec 26 2018 16:28
Then you gotta run sudo apt-get update first
Jason Luboff
@JLuboff
Dec 26 2018 16:29
Good call :thumbsup:
alpox
@alpox
Dec 26 2018 16:30
And with mit-scheme you get into the scheme repl
Where you can throw in code
(basically a terminal that accepts scheme code)
Jason Luboff
@JLuboff
Dec 26 2018 16:31
Neat
Does this also install a compiler?
alpox
@alpox
Dec 26 2018 16:32
Ehm scheme doesnr have a compiler
It has a reader and an evaluator
Jason Luboff
@JLuboff
Dec 26 2018 16:33
Ah.. I had been reading the install instructions last week (http://www.gnu.org/software/mit-scheme/documentation/mit-scheme-user/Unix-Installation.html ) and it mentions a compiler, but thats actually for C
alpox
@alpox
Dec 26 2018 16:34
If you mean to run a script it would be mit-scheme --quiet < somefile.scm
Yeaa that would be to compile the c sources of mit-scheme
Jason Luboff
@JLuboff
Dec 26 2018 16:36
Alright cool, thanks for the help, looks like I'm up and running :)
alpox
@alpox
Dec 26 2018 16:39
Youre welcome :)
Markus Kiili
@Masd925
Dec 26 2018 16:45
Yo.
Jason Luboff
@JLuboff
Dec 26 2018 16:47
I still find the syntax for compound expressions in Scheme to be odd...but..for some reason satisfying lol
@Masd925 Yo what up
Markus Kiili
@Masd925
Dec 26 2018 16:47
@JLuboff Trying to solve tic-tac-toe using Monte-Carlo. Almost there.
Jason Luboff
@JLuboff
Dec 26 2018 16:47
Whats monte-carlo?
Markus Kiili
@Masd925
Dec 26 2018 16:52
Algorithm that uses random results (plays random tic-tac-toe games here) and keeps track of how different moves win/lose. Then is starts to play more those moves that win more. Not the best algorithm for such a simple game (min-max would work too), but M-C works also for complex games where you cannot go through all possibilities (chess, go, etc).
Jason Luboff
@JLuboff
Dec 26 2018 16:52
Ah
So sort of an AI algorithm?
Markus Kiili
@Masd925
Dec 26 2018 16:53
Not sure how people like to define AI. Maybe it is.
Jason Luboff
@JLuboff
Dec 26 2018 16:54
I guess from the standpoint that it "learns"? I dunno
Markus Kiili
@Masd925
Dec 26 2018 16:55
One definition is machine doing something that men do.
Jason Luboff
@JLuboff
Dec 26 2018 17:02
Indeed..
Markus Kiili
@Masd925
Dec 26 2018 17:06
What are you up to?
Jason Luboff
@JLuboff
Dec 26 2018 17:08
Working on my React App.. first part is nearing completion just a few fixes here and there on it.
BP
@bgq007
Dec 26 2018 17:10
@JLuboff …. Whats the app?
Anyone know of any good (for beginners) React Books?
I just started the React section on FCC and I am taking some time to watch some YouTube videos (by The Net Ninja) on React.
Mohammed Boudad
@matrixersp
Dec 26 2018 17:13
@bgq007 I'm reading "React Cookbook" by Carlos Santana Roldan, I think it's a great book
BP
@bgq007
Dec 26 2018 17:14
@matrixersp … Ill look that one up. Thanks.
Jason Luboff
@JLuboff
Dec 26 2018 17:14
It's an app for work. Basic premise is workers have to currently fill out a form for jobs they will be performing which accounts for hazards and what the control(s) for that hazard maybe. I'm turning that into a digital form that has all potential hazards/controls for the individual to select and then it'll generate a printer friendly form. The second part will be having a template area that workers can select a template and just have to specify their name, date, and location and that template will autogenerate everything else
Mohammed Boudad
@matrixersp
Dec 26 2018 17:14
@bgq007 Any time
enestatli
@enestatli
Dec 26 2018 18:34
const increment = (function() {
  "use strict";
  return function increment(number, value=1) {
    return number + value;
  };
})();
console.log(increment(5, 2)); // returns 7
console.log(increment(5)); // returns 6
increment is declared as const variable
but we again declare it inside function
how possible?
Brad
@bradtaniguchi
Dec 26 2018 18:37
@enestatli The increment variable is "different" within each context.
Jason Luboff
@JLuboff
Dec 26 2018 18:37
I'm wondering why its an IIFE
Brad
@bradtaniguchi
Dec 26 2018 18:37
The "global context" is the const increment and it is being assigned a function, WITHIN that function's context, there is another variable named increment, which is also a function.
The inner function is kinda useless tho, it's a named function, but nothing can use that name within the same context
BP
@bgq007
Dec 26 2018 18:45
@JLuboff is it really an IIFE?
enestatli
@enestatli
Dec 26 2018 18:46
@bradtaniguchi thank you man
Jason Luboff
@JLuboff
Dec 26 2018 18:46
@bgq007 Sure looks like one to me...
BP
@bgq007
Dec 26 2018 18:47
@JLuboff thought they started with a (
Brad
@bradtaniguchi
Dec 26 2018 18:47
Yea it is. It's just the returned value is being assigned to a variable
BP
@bgq007
Dec 26 2018 18:47
but I’m a noob
Brad
@bradtaniguchi
Dec 26 2018 18:48
I've seen this pattern when doing "module-like" sorta stuff.
Jason Luboff
@JLuboff
Dec 26 2018 18:48
@bgq007 It does start with an (
BP
@bgq007
Dec 26 2018 18:51
I see that now… after the const declaration … i thought they had to start that way (first character of line)
Brad
@bradtaniguchi
Dec 26 2018 18:53
@bgq007 The idea is more abstract than that, this is the "key syntax": (/*stuff*/)() just like someThingToExecute()
except the first pair of parenthsis has what needs to be "executed"
BP
@bgq007
Dec 26 2018 19:17
Im watching these React videos and all I can think about is “This seems like adding more code and confusion. Why don’t we just use vanila js."
enestatli
@enestatli
Dec 26 2018 19:18
const AVG_TEMPERATURES = {
  today: 77.5,
  tomorrow: 79
};

function getTempOfTmrw(avgTemperatures) {
  "use strict";
  // change code below this line
  const {tomorrow:tempOfTomorrow} = AVG_TEMPERATURES; // change this line
  // change code above this line
  return tempOfTomorrow;
}

console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79
this test gives error
Jason Luboff
@JLuboff
Dec 26 2018 19:19
You should be using avgTemperatures not AVG_TEMPERATURES
enestatli
@enestatli
Dec 26 2018 19:19
lol, thank you :D
Aditya
@ezioda004
Dec 26 2018 19:52

I'm wondering why its an IIFE

Previously fcc wasnt using babel, so for some ES6 tests the IIFE was needed but its not needed anymore

Jason Luboff
@JLuboff
Dec 26 2018 19:53
Oh... didn't realize it was from FCC.. lol
Mohammed
@mhoorzook
Dec 26 2018 20:31
function isLess(a, b) {
  // Fix this code

  return 10<15, 15<10;
}


// Change these values to test
isLess(10, 15);
isLess(10,15) should return true
I need help returning 2 booleans
BP
@bgq007
Dec 26 2018 20:32
@mhoorzook don’t you want to do something like return a < b ? a, b : b, a
(returning only a or b depending on your ternary direction)
`function isLess(a,b) {
arg… Sorry, not familiar with Gitter and how to do code or soft returns (non-submit)
function isLess(a,b) { return a < b ? a : b; }
Mohammed
@mhoorzook
Dec 26 2018 20:38
Thanks, Let me give this a try @bgq007
BP
@bgq007
Dec 26 2018 20:43
and if you need to return the boolean, replace the a with true and b with false
after the ?
Brad
@bradtaniguchi
Dec 26 2018 20:51
^If your ternary has true/false as the results, don't use the ternary, just use the evaluated result: return a < b is enough
Mohammed
@mhoorzook
Dec 26 2018 20:54
I have tried using code return a < b
I have tried using code return a < b - It returns true but at the same time in the same function, I need to return a false boolean for `return b < a'
I have tried using return a < b - It returns True which is great... but at the same time using the same function, I need to return a false boolean for return b < a
Brad
@bradtaniguchi
Dec 26 2018 20:57
@mhoorzook So the function needs to return false if either a OR b is less than the other right?
it doens't matter if either are "less" than the other one?
Mohammed
@mhoorzook
Dec 26 2018 21:06
function isLess(a, b) {
  // Free Code Camp - Cannot use If/Else statements for this

return 10<15; // This returns true 
return 15<10; // I am failing to return False here
}
 // INSTRUCTIONS 
  /* > Fix the below code WITHOUT using IF/ELSE 
     > isLess(10,15) should return true
     > isLess(15,10) should return false */

function isLess(a, b) {


// Correct the below code 
  if (a < b) {
    return true;
  } else {
    return false;
  }
}

// You can change these values to run tests 
isLess(10, 15);
Mohammed
@mhoorzook
Dec 26 2018 21:18
Im so silly, I cannot believe I have spent over an hour trying to figure this out
@bradtaniguchi You were right with return a < b - My bad, thank you
Jason Luboff
@JLuboff
Dec 26 2018 21:24
@mhoorzook You can not have two return in the same function unless they are nested within logic (i.e if/else statement). The second return in your above example (the first code block) would never be reached no matter what
Brad
@bradtaniguchi
Dec 26 2018 21:35
@mhoorzook Np, another anti-pattern to keep an eye for is the if (/condition/) {return true} else {return false} or some varient. Just return the condition to get true/false
Jason Luboff
@JLuboff
Dec 26 2018 21:36
Some true shit right there ^^^
Mohammed
@mhoorzook
Dec 26 2018 22:11
Noted. Thank you so much for the tips @JLuboff & @bradtaniguchi - Learning a lot from amazing people like you.
Brad
@bradtaniguchi
Dec 26 2018 22:11
np :D
Jason Luboff
@JLuboff
Dec 26 2018 22:19
:thumbsup:
@bradtaniguchi You got the office to yourself this week?
Brad
@bradtaniguchi
Dec 26 2018 22:25
@JLuboff I'm home haha, one of my coworkers is working tho, so he's got it all to himself. Today is my "only" day I'm working taking off till the 2nd
Jason Luboff
@JLuboff
Dec 26 2018 22:26
Ah..
Brad
@bradtaniguchi
Dec 26 2018 22:26
@JLuboff whataboutyou
Jason Luboff
@JLuboff
Dec 26 2018 22:26
In the office.. decent number of people still here. In my direct team (4 people), its only me and my manager
Brad
@bradtaniguchi
Dec 26 2018 22:28
that sounds about right, you must be the hard working one to be there today haha :P
Jason Luboff
@JLuboff
Dec 26 2018 22:29
Eh.... lol
I had some vacation time left but didn't schedule it in time so cashed it out
BP
@bgq007
Dec 26 2018 22:36
Well…. I was right too. lol
Brad
@bradtaniguchi
Dec 26 2018 22:36
Ah I see, I've been spending it more or less the moment I get my vacation time, after taking this time off I have 0 until like end of feb
Jason Luboff
@JLuboff
Dec 26 2018 22:37
I had I think 30 hours left :shrug: was a decent payout
Brad
@bradtaniguchi
Dec 26 2018 22:40
So you just get paid for the vacation time, but take no vacation right?
Jason Luboff
@JLuboff
Dec 26 2018 22:41
Ya, can only do it with up to 40 hours
Idowu Wasiu
@Hoxtygen
Dec 26 2018 22:41
hi guys. mind helping a lost soul here?
Jason Luboff
@JLuboff
Dec 26 2018 22:43
Perhaps we can
Idowu Wasiu
@Hoxtygen
Dec 26 2018 22:44
I'm writing an integration testing for a nodejs with postgres as the database.... Below is my code

describe('Add a book to the database', () => {
  it('should add a book to the database', (done) => {
    const item = {
      title: 'The green misadventure',
      pubYear: 2013,
      publisher: 'Drogba books',
      author_id: 19,
      category_id: 10,
      image_url: 'http://i38.photobucket.com/albums/e143/hoxtygen/omething_zpsmi1s5uyhg.jpg',
    };
    chai.request('http://localhost:5001')
      .post('/api/v1/books')
      .send(item)
      .end((err, res) => {
        console.log(res);
        res.should.have.status(201);
        done();
      });
  });
});
Though the test passes, somehow dubious I must say but I'm getting this error
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:470:11)
    at ServerResponse.header (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\response.js:767:10)
    at ServerResponse.send (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\response.js:170:12)
    at ServerResponse.json (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\response.js:267:15)
    at update (C:/Users/Hoxtygen/Documents/WebDevelopment/projects/MERN/Library/server/controllers/booksController.js:129:28)
    at Layer.handle [as handle_request] (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\layer.js:95:5)
    at C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:281:22
    at param (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:354:14)
    at param (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:365:14)
    at Function.process_params (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:410:3)
    at next (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:275:10)
    at Function.handle (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:174:3)
    at router (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:47:12)
    at Layer.handle [as handle_request] (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:317:13)
    at C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:275:10)
    at C:/Users/Hoxtygen/Documents/WebDevelopment/projects/MERN/Library/server/server.js:20:3
    at Layer.handle [as handle_request] (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:317:13)
    at C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\index.js:275:10)
    at jsonParser (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\body-parser\lib\types\json.js:119:7)
    at Layer.handle [as handle_request] (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\Hoxtygen\Documents\WebDevelopment\projects\MERN\Library\node_modules\exp
Jason Luboff
@JLuboff
Dec 26 2018 22:47
Are you sending a response back to the browser?
Idowu Wasiu
@Hoxtygen
Dec 26 2018 22:47
It's actually pointing here
app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  next();
});
@JLuboff not using a browser
It's actually pointing here
app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  next();
});
Jason Luboff
@JLuboff
Dec 26 2018 22:48
In that case..it seems to be your middleware is getting hit after the test...but.. I've never messed with testing so maybe @bradtaniguchi has some better insight
Idowu Wasiu
@Hoxtygen
Dec 26 2018 22:48

It's actually pointing here

app.use((req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  next();
});

I use this code to control cors

Brad
@bradtaniguchi
Dec 26 2018 22:49
That error usually happens when you do something like this:
app.use('/whatever', (req,res) => {
  res.send('blah');
// other logic/code whatever
res.send('other stuff'); // you already "sent stuff, but its gone"
});
This only happens during a test I assume right?
@Hoxtygen
Idowu Wasiu
@Hoxtygen
Dec 26 2018 22:50
@bradtaniguchi yes, during testing
Brad
@bradtaniguchi
Dec 26 2018 22:52
You sure thats where the error is pointing you? That's this file: /server/server.js:20:3(only thing I can pull out from the stack that looks like your code)
Oh wait, its this line right you posted? booksController.js:129:28
Idowu Wasiu
@Hoxtygen
Dec 26 2018 22:54
@bradtaniguchi I had copied the post test code out of the testing file so i can run other tests without it interfering
@bradtaniguchi line 20:3 points to next()
@bradtaniguchi let me push the branch I'm working on to github so you can see the whole picture
Brad
@bradtaniguchi
Dec 26 2018 22:57
I think were missing the bigger picture here of when the "next" is called/used. I believe the error is on the context, not the code. As I mentioned earlier the error that express is spitting out usually is because your calling res.send or something multiple times. Not sure where this "next" code comes in, but the error is where this code is called
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:02
@bradtaniguchi will look into it, however, without the next() all my tests fail spectacularly
Brad
@bradtaniguchi
Dec 26 2018 23:06
Not saying the next is the issue. I personally have our tests setup in a way where we don't use any middleware, which is a good and bad thing. The good is we can write simplier tests since were skipping some validation here and there, but then we need to test the "full" thing at another time
Jason Luboff
@JLuboff
Dec 26 2018 23:06
Or just be like me and dont test :P :joy:
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:08
@JLuboff will you hire me? no job yet, and the job market seems to have gazillion requirements, even for internships
Jason Luboff
@JLuboff
Dec 26 2018 23:09
I'm the only programmer/database guy here and have no hiring power hah
But don't take me serious about tests, they are important and I would like to get into writing them
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:11
@JLuboff kind of sucks hitting brick at every implementation of anything..... sighs!
Brad
@bradtaniguchi
Dec 26 2018 23:12
@Hoxtygen If you aren't failing, you aren't learning
Jason Luboff
@JLuboff
Dec 26 2018 23:12
Thats how it goes...I hit bricks often...then I get my chisel and chisel them away
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:13
@bradtaniguchi yeah. Was here earlier today and was helped out and pointed to the right resources. And then I was winging it only to get shot down by the current problem
@JLuboff my brick seem too much, either I'm taking on project beyond my current knowledge or I'm totally clueless
Brad
@bradtaniguchi
Dec 26 2018 23:17
1 step at a time, you know a few thing's Im sure. Whatever you do know is your foundation to start getting to the next level. I always try to take on projects beyond my current level. Fastest way to grow
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:18
I'm just going to suspend the TravisCI badge on my repo. Sends me tons of mails telling my tests are failing each time I push to github. I need to move on
Brad
@bradtaniguchi
Dec 26 2018 23:18
@Hoxtygen I'd fix the tests no?
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:19
@bradtaniguchi Thanks man..... will fix it sure..... I've just got many other things to implement
Brad
@bradtaniguchi
Dec 26 2018 23:19
Hehe speaking of tests I'm trying to get mine to work too haha.
@Hoxtygen Yea I mean you gotta do what you gotta do
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:20

@Hoxtygen Yea I mean you gotta do what you gotta do

yes.

@bradtaniguchi @JLuboff any such thing as remote internship?
Jason Luboff
@JLuboff
Dec 26 2018 23:21
I wanted to learn React.. so.. my current work project is being written in React. Right now...its awful :) But I'm learning and will refactor as I go along/later
I've never done an internship, so not sure
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:21
@JLuboff I mean do companies take interns remotely?
Brad
@bradtaniguchi
Dec 26 2018 23:22
I've done an internship, but I personally have never heard of a remote one
I mean id consider it possible, there are entire companies which are more or less remote, but idk how common they are that also have remote internships
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:24
@bradtaniguchi I'm just going to try my luck at one, hopefully I hit a jackpot. Problem is I don't even know any to apply to now
Jason Luboff
@JLuboff
Dec 26 2018 23:24
I would think they aren't very common...
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:26
@JLuboff I'm gonna keep diggging and fishing for one.
Brad
@bradtaniguchi
Dec 26 2018 23:26
I'd consider it easier to get an entry level remote job, but even that isn't common either. Freelancing might be the easiest, but then its more or less on you
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:28
@bradtaniguchi I'd prefer entry level or internship.... I've got limited time to learn which affects my learning. I've got an 8-5 job that
Jason Luboff
@JLuboff
Dec 26 2018 23:28
So start applying for everything and anything!
Brad
@bradtaniguchi
Dec 26 2018 23:28
^
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:29
a job thats no longer appealing, monotonous and repetitive and has no relationship to computer science.... wanna take a guess?
Jason Luboff
@JLuboff
Dec 26 2018 23:29
warehouse work?
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:30
@JLuboff not even close..... Ever been to the hospital for surgery?
Jason Luboff
@JLuboff
Dec 26 2018 23:30
Yup
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:31
@JLuboff I'm one of those fuckers who makes sure you dont feel a thing while you're being operated on
Jason Luboff
@JLuboff
Dec 26 2018 23:31
anesthesiologist?
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:32
@JLuboff damn right, but I'm just an assistant as my major is Human Anatomy
Jason Luboff
@JLuboff
Dec 26 2018 23:33
Here in the US... thats a pretty nice salary ($95k - $180k)...
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:34
@JLuboff hahahha, not here, not even close..... but it's not about the salary, it's about the job itself..... almost the same thing over and over again..... thats not my thing
Jason Luboff
@JLuboff
Dec 26 2018 23:35
Fair enough :)
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:37
gotta go man, its 12:36am here, have to be up by 5:30am
Jason Luboff
@JLuboff
Dec 26 2018 23:37
Ouch, get some rest
Brad
@bradtaniguchi
Dec 26 2018 23:37
@Hoxtygen C ya, goodluck and get rest :D
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:37
@JLuboff will soon be here with other problems.... that I can promise you
Jason Luboff
@JLuboff
Dec 26 2018 23:38
You'll conquer them if you believe you will ;)
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:38
@JLuboff with you guys here I believe I can never walk alone
Jason Luboff
@JLuboff
Dec 26 2018 23:39
:thumbsup:
Brad
@bradtaniguchi
Dec 26 2018 23:41
Yas CircleCi works with the main project now :sunglasses: only had to turn off like 25% of the failing tests due to them being too old XD, gotta go fix all those..
Jason Luboff
@JLuboff
Dec 26 2018 23:42
Sweet.. although I don't know what that is
Idowu Wasiu
@Hoxtygen
Dec 26 2018 23:43
@JLuboff those are for continuous integration..... Lotta buzzword
Brad
@bradtaniguchi
Dec 26 2018 23:43
@JLuboff this thing:https://circleci.com/
Jason Luboff
@JLuboff
Dec 26 2018 23:44
I just see fancy graphics and words :P
Brad
@bradtaniguchi
Dec 26 2018 23:46
TLDR is every time you push to github (or where ever you host the code) circleci will get notified, pull the changes, automatically run tests/ do whatever you want in a docker-container (yours or a built in) and then potentially deploy (using docker, or a cloud service, manually) to your server.
Jason Luboff
@JLuboff
Dec 26 2018 23:46
Oh thats pretty dope
Brad
@bradtaniguchi
Dec 26 2018 23:46
the ci is for Continuous Integration, as Idowu said
And CI really just means "merge your branches as often as possible yo!"
catch all the errors and issues earlier, rather than merging everything later (thats where bugs appear and issues come up)
My dream app is having like 100% code coverage, testing everything, writing code+tests, going to circleCi, having it test everything hardcore and automatically deploying to anything and everything :sunglasses:
Jason Luboff
@JLuboff
Dec 26 2018 23:48
Gah...everytime you talk about shit like this..I want to learn how to integrate tests lol
Brad
@bradtaniguchi
Dec 26 2018 23:49
It's kinda addicting XD, The last project I hooked up had so much focus on testing and getting that "100%" I kinda forgot the app sucked XD
Jason Luboff
@JLuboff
Dec 26 2018 23:49
haha
Jason Luboff
@JLuboff
Dec 26 2018 23:55
@bradtaniguchi I may have a question for you that'll be right up your alley
Brad
@bradtaniguchi
Dec 26 2018 23:55
Yea sure :D
Jason Luboff
@JLuboff
Dec 26 2018 23:55
It involves flattening an array
Using... reduce!
Brad
@bradtaniguchi
Dec 26 2018 23:56
Ah yes, the only array operator :P
Jason Luboff
@JLuboff
Dec 26 2018 23:58
Alright! I got it to flatten...but..it's not pretty...
Brad
@bradtaniguchi
Dec 26 2018 23:59
thats never a good thing to say XD