Open atherdon opened 6 years ago
damn, i missed that you started to work on tests. but jest is a bit similar thing, so hope this will not be a trouble
@atherdon should I overwrite the tests that are already done and use jest instead of mocha?
yes, it's part of the plan. mocha is more default test engine for api endpoints, but as we're using jest at react part - i think it's more clear to use one thing for front and back. i'm trying to get my hands clean and reply to your prev comments, but still busy. hope this is not a problem
we also will be able to move that jest tests into our main projects. so your tests code will improve Groceristar and ChickenKyiv soon ;)
@atherdon don't worry, I'm a little bussy too :) I can work with this information, thanks!
good to know, becuase i'm started to feel guilty :)
@atherdon are we going to use any framework specifically? I have found this article about api testing with Jest but if in yout api you are using another way for the tests I prefer to be familiarized with it
we didn't setup a tests in main projects properly. but i'm a big fan of tests - so we'll do it together. so it's like a blank page right now. how we'll setup it - it'll works.
your tests looks good. i assume you soon will finish full transition from chai to jest, right? or it's done right now
@atherdon I have to do it properly yet, for the momento I have only the base. I will try to end it in one or two days, I have been a bit bussy.
Sure, we don't have rush here.
On 03-Jun-2018 at 07:13 PM, JorgeRodr wrote:
@atherdon https://github.com/atherdon I have to do it properly yet, for the momento I have only the base. I will try to end it in one or two days, I have been a bit bussy.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ChickenKyiv/loopback-tutor-intern-18/issues/8#issuecomment-394184383, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZrDq4bxhPkpSteOV2LrDYzvUPjMMv-ks5t5DVpgaJpZM4UGNhz .
@atherdon it happens that chai can be used with JEST too so I'm going to follow that way. Now I have only one useful test, I want to solve a disconnect issue before doing the rest. What is happening is that the console throws this error when tests are done
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● PROMISE
at Promise.catch (<anonymous>)
And it doesn't exit the process. I will do a research but it seems some problem with a promise in the reservation.js.
i'll take a look at that metohd - can you share me a code line?
On 03-Jun-2018 at 08:25 PM, JorgeRodr wrote:
@atherdon https://github.com/atherdon it happens that chai can be used with JEST too so I'm going to follow that way. Now I have only one useful test, I want to solve a disconnect issue before doing the rest. What is happening is that the console throws this error when tests are done
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● PROMISE
at Promise.catch (<anonymous>)
And it doesn't exit the process. I will do a research but it seems some problem with a promise in the reservation.js.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ChickenKyiv/loopback-tutor-intern-18/issues/8#issuecomment-394188760, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZrDlnsYmpVxBDxqEdu2YJdYu8XNp2fks5t5EYdgaJpZM4UGNhz .
@atherdon sorry, I think that it is a different problem not with the reservation.js. It is something like what they are talking here:
https://github.com/strongloop/loopback/issues/1538
I have to test a few things first, but I found a workaraound passing the --forceExit tag to jest command for tests.
got it. it's nice that you figure it out. i'm not a pro with js tests, but willing to learn more too
On Mon, Jun 4, 2018 at 1:09 AM, JorgeRodr notifications@github.com wrote:
@atherdon https://github.com/atherdon sorry, I think that it is a different problem not with the reservation.js. It is something like what they are talking here:
strongloop/loopback#1538 https://github.com/strongloop/loopback/issues/1538
I have to test a few things first, but I found a workaraound passing the --forceExit tag to jest command for tests.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ChickenKyiv/loopback-tutor-intern-18/issues/8#issuecomment-394195478, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZrDnvTCKjZg6dRUw_VjlCft2CzHEvcks5t5F6AgaJpZM4UGNhz .
@atherdon In order to continue the tests I need an admin user for the requests that need authentication. I've been searching in the docs and the only thing I have found is to create users in the boot scripts and then assign to them the admin role. But I think that is more interesting to add to the customer a field where you can tell to the api if the user is admin or not and then create it with that role. Do you have any example of this functionality?
no i haven't this example, but let's discuss this feature here, why not :) So you want to add a field to your model, that is child of UserModel of Loopback, right? this field will be flag? like boolean yes, no? and when user is created by some methods - we call in callback another method, that bind admin role? am i understand this correct?
btw, i can show you an example of import users. i think we have more advanced example how to create users and assign admin role... but i plan to share it a bit later - you can find a task with 'automigrate' in title. but maybe this is a right time
On 04-Jun-2018 at 08:32 PM, JorgeRodr wrote:
@atherdon https://github.com/atherdon In order to continue the tests I need an admin user for the requests that need authentication. I've been searching in the docs and the only thing I have found is to create users in the boot scripts and then assign to them the admin role. But I think that is more interesting to add to the customer a field where you can tell to the api if the user is admin or not and then create it with that role. Do you have any example of this functionality?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ChickenKyiv/loopback-tutor-intern-18/issues/8#issuecomment-394489433, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZrDmQA9PHa7eqGJqKhDW9-r4v_rRHuks5t5Zl6gaJpZM4UGNhz .
This is exactly what I am planning. The problem is that I have a route for the customer's post method but I can't reach it. I will search for a solution tomorrow.
On Mon, Jun 4, 2018 at 10:36 PM, Arthur Tkachenko notifications@github.com wrote:
no i haven't this example, but let's discuss this feature here, why not :) So you want to add a field to your model, that is child of UserModel of Loopback, right? this field will be flag? like boolean yes, no? and when user is created by some methods - we call in callback another method, that bind admin role? am i understand this correct?
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/ChickenKyiv/loopback-tutor-intern-18/issues/8#issuecomment-394490551, or mute the thread https://github.com/notifications/unsubscribe-auth/AloqqaHt0vAMslxbU88mMBjcadJrOb7oks5t5ZpMgaJpZM4UGNhz .
show me code link. it's hard to see what you're doing without code
On 04-Jun-2018 at 09:46 PM, JorgeRodr wrote:
This is exactly what I am planning. The problem is that I have a route for the customer's post method but I can't reach it. I will search for a solution tomorrow.
On Mon, Jun 4, 2018 at 10:36 PM, Arthur Tkachenko notifications@github.com
wrote:
no i haven't this example, but let's discuss this feature here, why not :) So you want to add a field to your model, that is child of UserModel of Loopback, right? this field will be flag? like boolean yes, no? and when user is created by some methods - we call in callback another method, that bind admin role? am i understand this correct?
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub < https://github.com/ChickenKyiv/loopback-tutor-intern-18/issues/8#issuecomment-394490551>,
or mute the thread < https://github.com/notifications/unsubscribe-auth/AloqqaHt0vAMslxbU88mMBjcadJrOb7oks5t5ZpMgaJpZM4UGNhz>
.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ChickenKyiv/loopback-tutor-intern-18/issues/8#issuecomment-394510528, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZrDuWGQXpxuotzOVKG-NIZrpIA5Yrtks5t5aq6gaJpZM4UGNhz .
@atherdon I have not pushed it yet but I have a file called customers.controller.js and the code inside is something like this:
module.exports = function(server) {
var router = server.loopback.Router();
router.post("/customers", (req, res, next) => {
console.log(req);
});
server.use(router);
};
Ok, so this is just a simple router. what do you want to put there? some User.find()
method, right?
I want to create the customer there and then in the callback assign the role to the created user.
El mar., 5 jun. 2018 9:56, Arthur Tkachenko notifications@github.com escribió:
Ok, so this is just a simple router. what do you want to put there? some User.find() method, right?
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/ChickenKyiv/loopback-tutor-intern-18/issues/8#issuecomment-394616992, or mute the thread https://github.com/notifications/unsubscribe-auth/AloqqT7MFaH9awm6RaHX65y13rt_ZgTkks5t5jmhgaJpZM4UGNhz .
got it. I think i have a better way for importing users. will share it with you soon
Thanks!
El mar., 5 jun. 2018 10:47, Arthur Tkachenko notifications@github.com escribió:
got it. I think i have a better way for importing users. will share it with you soon
On 05-Jun-2018 at 08:45 AM, JorgeRodr wrote:
I want to create the customer there and then in the callback assign the role to the created user.
El mar., 5 jun. 2018 9:56, Arthur Tkachenko notifications@github.com escribió:
Ok, so this is just a simple router. what do you want to put there? some User.find() method, right?
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub <
https://github.com/ChickenKyiv/loopback-tutor-intern-18/issues/8#issuecomment-394616992
,
or mute the thread <
.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub < https://github.com/ChickenKyiv/loopback-tutor-intern-18/issues/8#issuecomment-394630963
, or mute the thread < https://github.com/notifications/unsubscribe-auth/ABZrDqzfc5etsJOZ1kMm0rnn9taIOe1Yks5t5kUtgaJpZM4UGNhz
.
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/ChickenKyiv/loopback-tutor-intern-18/issues/8#issuecomment-394631544, or mute the thread https://github.com/notifications/unsubscribe-auth/AloqqQSG1aO5wr30ofEVVvP3aT8WXLN6ks5t5kWmgaJpZM4UGNhz .
here you can see an example how we importing data right now: https://github.com/ChickenKyiv/loopback-tutor-intern-10/tree/master/bin
we put it separately just for make code more clear. and you can call it from package.json scripts
@atherdon I will try to use your solution. Wish me luck haha
@atherdon Ok, I did it. In part at least haha I will tell you what is the problem now:
When I create the usea, I search for an admin role and if it does exist, I just create the principal for the user id. But when I log in as this user, the token returned doesn't seem to be a validone for authenticated request. For example, I'm trying to create a reservation with that token and it throw an Auth error.
You can see my code here: https://github.com/ChickenKyiv/loopback-tutor-intern-18/blob/3fc3b51c6f61c5a21fc95f8d89baef3c0ea2bf14/server/models/customer.js#L5
Sorry for this slow motion developing but I don't have so much time right now, I have learned a lot of things though and I appreciate your time.
BETTER GRAB A BEER ^) i like your progress - you're doing great - will try to check your code soon.
@atherdon Still no idea why token isn't valid, but I understand a little better how roles work. The token issue is the only blind point.
can you show me screenshot, maybe video - because each time i'm trying to guess what is not working and how to help you :)
@atherdon The problem is that I have an admin user but I cannot make authorized requests.
Here is my acl for campagrounds:
I have an admin user and when I login the request returns a token. I use that token in the post request to create a campground (I insert the token as an access_token header) but it throws this error:
{
"error": {
"statusCode": 401,
"name": "Error",
"message": "Autorización necesaria",
"code": "AUTHORIZATION_REQUIRED"
}
}
I have checked the db with robomongo and I have the correct role created, in the RoleMapping collection all seems ok, and the users seems ok too. I have no idea what is happening hahaha.
just delete acl - will it work?
@atherdon If I delete acl it works, yes. Should I continue without acl?
it's not the best option for sure, but at least it works, so we don't need to stuck on it right now.
hey @atherdon I have done some tests in campagrounds and reservations. Not a lot but I think I prefer to end this part the tutorial and continue with the other issues.
can you move that code into repository? i cannot find it
@atherdon mmm It seems there was a problem pushing the code. I'm not at home now but I will solve it later. Sorry!
no problem
On 15-Jun-2018 at 06:39 AM, JorgeRodr wrote:
@atherdon https://github.com/atherdon mmm It seems there was a problem pushing the code. I'm not at home now but I will solve it later. Sorry!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ChickenKyiv/loopback-tutor-intern-18/issues/8#issuecomment-397528292, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZrDnleJZwm3_t8hJ12ICEftjgsvCA1ks5t81axgaJpZM4UGNhz .
i think i just forget that youre working at develo branch - we should use PRs more often ;) will take a look
@atherdon yeah I have been working on develop branch hahaha, I can work on feature branches and then use PRs if you want
i think we should keep develop branch, just create a featured braches from develop and use PRs in order to keep me in loop of your changes. it'll be less confusing for me. because i'm jumping between repositories and it's hard to keep all in my head ;)
On 16-Jun-2018 at 10:15 AM, JorgeRodr wrote:
@atherdon https://github.com/atherdon yeah I have been working on develop branch hahaha, I can work on feature branches and then use PRs if you want
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ChickenKyiv/loopback-tutor-intern-18/issues/8#issuecomment-397802825, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZrDkt_XjDpNdP1_FqSbAsPJyfrG2s-ks5t9NrZgaJpZM4UGNhz .
for testing custom methods api endpoints - not for all generated endpoints. not finished task - can be discussed in comments