From 2e651f285ec7a63ae103e12a4e17b52f5cc1e1e9 Mon Sep 17 00:00:00 2001 From: Ravi kumar <1002kumarravi@gmail.com> Date: Thu, 3 Aug 2023 07:11:30 +0530 Subject: [PATCH 1/5] add: github created at key in db for new joiner --- controllers/auth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/auth.js b/controllers/auth.js index b3073bd41..8cf7c5c65 100644 --- a/controllers/auth.js +++ b/controllers/auth.js @@ -49,10 +49,10 @@ const githubAuthCallback = (req, res, next) => { logger.error(err); return res.boom.unauthorized("User cannot be authenticated"); } - userData = { github_id: user.username, github_display_name: user.displayName, + github_created_at: user._json.created_at, }; const { userId, incompleteUserDetails } = await users.addOrUpdate(userData); From 8d18645b9c3217fff810adf02eb134c802cab5d0 Mon Sep 17 00:00:00 2001 From: Ravi kumar <1002kumarravi@gmail.com> Date: Fri, 4 Aug 2023 11:18:28 +0530 Subject: [PATCH 2/5] fix: convert date type into unix timestamp --- controllers/auth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/auth.js b/controllers/auth.js index 8cf7c5c65..77aeaa040 100644 --- a/controllers/auth.js +++ b/controllers/auth.js @@ -52,7 +52,7 @@ const githubAuthCallback = (req, res, next) => { userData = { github_id: user.username, github_display_name: user.displayName, - github_created_at: user._json.created_at, + github_created_at: Number((new Date(user._json.created_at).getTime() / 1000).toFixed(0)), }; const { userId, incompleteUserDetails } = await users.addOrUpdate(userData); From b1abccb502147dfb420e06ff331216bfcaa15dec Mon Sep 17 00:00:00 2001 From: Ravi kumar <1002kumarravi@gmail.com> Date: Sun, 6 Aug 2023 18:44:42 +0530 Subject: [PATCH 3/5] fix: Unix Timestamp method --- controllers/auth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/auth.js b/controllers/auth.js index e038e1226..9c6554f68 100644 --- a/controllers/auth.js +++ b/controllers/auth.js @@ -52,7 +52,7 @@ const githubAuthCallback = (req, res, next) => { userData = { github_id: user.username, github_display_name: user.displayName, - github_created_at: Number((new Date(user._json.created_at).getTime() / 1000).toFixed(0)), + github_created_at: Number(new Date(user._json.created_at).getTime()), created_at: Date.now(), updated_at: Date.now(), }; From 36edb2479e75a5e18309752848513c12189c1f4c Mon Sep 17 00:00:00 2001 From: Ravi kumar <1002kumarravi@gmail.com> Date: Sun, 6 Aug 2023 19:15:53 +0530 Subject: [PATCH 4/5] feat: test for github_created_at fields --- test/fixtures/auth/githubUserInfo.js | 44 ++++++++++++++++++++++++++++ test/fixtures/user/user.js | 15 ++++++++++ test/unit/models/users.test.js | 8 +++++ 3 files changed, 67 insertions(+) diff --git a/test/fixtures/auth/githubUserInfo.js b/test/fixtures/auth/githubUserInfo.js index 153264e0a..bdf2ec452 100644 --- a/test/fixtures/auth/githubUserInfo.js +++ b/test/fixtures/auth/githubUserInfo.js @@ -101,5 +101,49 @@ module.exports = () => { created_at: "2020-09-06T16:21:38Z", updated_at: "2023-07-26T09:29:37Z", }, + { + id: "86847625", + nodeId: "MDQ6VXNlcjg2ODQ3NjI1", + displayName: "Ravi kumar", + username: "ravikumar1002", + profileUrl: "https://github.com/ravikumar1002", + photos: [{ value: "https://avatars.githubusercontent.com/u/86847625?v=4" }], + provider: "github", + _raw: '{"login":"ravikumar1002","id":86847625,"node_id":"MDQ6VXNlcjg2ODQ3NjI1","avatar_url":"https://avatars.githubusercontent.com/u/86847625?v=4","gravatar_id":"","url":"https://api.github.com/users/ravikumar1002","html_url":"https://github.com/ravikumar1002","followers_url":"https://api.github.com/users/ravikumar1002/followers","following_url":"https://api.github.com/users/ravikumar1002/following{/other_user}","gists_url":"https://api.github.com/users/ravikumar1002/gists{/gist_id}","starred_url":"https://api.github.com/users/ravikumar1002/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ravikumar1002/subscriptions","organizations_url":"https://api.github.com/users/ravikumar1002/orgs","repos_url":"https://api.github.com/users/ravikumar1002/repos","events_url":"https://api.github.com/users/ravikumar1002/events{/privacy}","received_events_url":"https://api.github.com/users/ravikumar1002/received_events","type":"User","site_admin":false,"name":"Ravi kumar","company":null,"blog":"https://ravikumar.dev/","location":"Delhi, India","email":null,"hireable":null,"bio":"Frontend developer","twitter_username":"kumarravi1002","public_repos":47,"public_gists":0,"followers":9,"following":13,"created_at":"2021-07-02T16:40:44Z","updated_at":"2023-07-27T00:12:32Z"}', + _json: { + login: "ravikumar1002", + id: 86847625, + node_id: "MDQ6VXNlcjg2ODQ3NjI1", + avatar_url: "https://avatars.githubusercontent.com/u/86847625?v=4", + gravatar_id: "", + url: "https://api.github.com/users/ravikumar1002", + html_url: "https://github.com/ravikumar1002", + followers_url: "https://api.github.com/users/ravikumar1002/followers", + following_url: "https://api.github.com/users/ravikumar1002/following{/other_user}", + gists_url: "https://api.github.com/users/ravikumar1002/gists{/gist_id}", + starred_url: "https://api.github.com/users/ravikumar1002/starred{/owner}{/repo}", + subscriptions_url: "https://api.github.com/users/ravikumar1002/subscriptions", + organizations_url: "https://api.github.com/users/ravikumar1002/orgs", + repos_url: "https://api.github.com/users/ravikumar1002/repos", + events_url: "https://api.github.com/users/ravikumar1002/events{/privacy}", + received_events_url: "https://api.github.com/users/ravikumar1002/received_events", + type: "User", + site_admin: false, + name: "Ravi kumar", + company: null, + blog: "https://ravikumar.dev/", + location: "Delhi, India", + email: null, + hireable: null, + bio: "Frontend developer", + twitter_username: "kumarravi1002", + public_repos: 47, + public_gists: 0, + followers: 9, + following: 13, + created_at: "2021-07-02T16:40:44Z", + updated_at: "2023-07-27T00:12:32Z", + }, + }, ]; }; diff --git a/test/fixtures/user/user.js b/test/fixtures/user/user.js index caf2735c5..7938c3271 100644 --- a/test/fixtures/user/user.js +++ b/test/fixtures/user/user.js @@ -343,5 +343,20 @@ module.exports = () => { updated_at: Date.now(), created_at: Date.now(), }, + { + username: "ravikumar1002", + first_name: "ravi", + last_name: "kumar", + github_id: githubUserInfo[2].username, + github_display_name: githubUserInfo[2].displayName, + github_created_at: Number(new Date(githubUserInfo[2]._json.created_at).getTime()), + roles: { + member: false, + in_discord: true, + }, + incompleteUserDetails: false, + updated_at: Date.now(), + created_at: Date.now(), + }, ]; }; diff --git a/test/unit/models/users.test.js b/test/unit/models/users.test.js index 42d7cad61..cf2ce3e77 100644 --- a/test/unit/models/users.test.js +++ b/test/unit/models/users.test.js @@ -102,6 +102,14 @@ describe("users", function () { expect(user).to.haveOwnProperty("updated_at"); expect(userExists).to.equal(true); }); + + it("It should have github_created_at fields", async function () { + const userData = userDataArray[15]; + await users.addOrUpdate(userData); + const githubUsername = "ravikumar1002"; + const { user } = await users.fetchUser({ githubUsername }); + expect(user).to.haveOwnProperty("github_created_at"); + }); }); describe("user image verification", function () { From 1b745bf9836400d546e2e11d56826064eb136343 Mon Sep 17 00:00:00 2001 From: Ravi kumar <1002kumarravi@gmail.com> Date: Mon, 7 Aug 2023 14:01:40 +0530 Subject: [PATCH 5/5] remove: extra fixtures data --- test/fixtures/auth/githubUserInfo.js | 44 ---------------------------- test/fixtures/user/user.js | 16 +--------- test/unit/models/users.test.js | 4 +-- 3 files changed, 3 insertions(+), 61 deletions(-) diff --git a/test/fixtures/auth/githubUserInfo.js b/test/fixtures/auth/githubUserInfo.js index bdf2ec452..153264e0a 100644 --- a/test/fixtures/auth/githubUserInfo.js +++ b/test/fixtures/auth/githubUserInfo.js @@ -101,49 +101,5 @@ module.exports = () => { created_at: "2020-09-06T16:21:38Z", updated_at: "2023-07-26T09:29:37Z", }, - { - id: "86847625", - nodeId: "MDQ6VXNlcjg2ODQ3NjI1", - displayName: "Ravi kumar", - username: "ravikumar1002", - profileUrl: "https://github.com/ravikumar1002", - photos: [{ value: "https://avatars.githubusercontent.com/u/86847625?v=4" }], - provider: "github", - _raw: '{"login":"ravikumar1002","id":86847625,"node_id":"MDQ6VXNlcjg2ODQ3NjI1","avatar_url":"https://avatars.githubusercontent.com/u/86847625?v=4","gravatar_id":"","url":"https://api.github.com/users/ravikumar1002","html_url":"https://github.com/ravikumar1002","followers_url":"https://api.github.com/users/ravikumar1002/followers","following_url":"https://api.github.com/users/ravikumar1002/following{/other_user}","gists_url":"https://api.github.com/users/ravikumar1002/gists{/gist_id}","starred_url":"https://api.github.com/users/ravikumar1002/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ravikumar1002/subscriptions","organizations_url":"https://api.github.com/users/ravikumar1002/orgs","repos_url":"https://api.github.com/users/ravikumar1002/repos","events_url":"https://api.github.com/users/ravikumar1002/events{/privacy}","received_events_url":"https://api.github.com/users/ravikumar1002/received_events","type":"User","site_admin":false,"name":"Ravi kumar","company":null,"blog":"https://ravikumar.dev/","location":"Delhi, India","email":null,"hireable":null,"bio":"Frontend developer","twitter_username":"kumarravi1002","public_repos":47,"public_gists":0,"followers":9,"following":13,"created_at":"2021-07-02T16:40:44Z","updated_at":"2023-07-27T00:12:32Z"}', - _json: { - login: "ravikumar1002", - id: 86847625, - node_id: "MDQ6VXNlcjg2ODQ3NjI1", - avatar_url: "https://avatars.githubusercontent.com/u/86847625?v=4", - gravatar_id: "", - url: "https://api.github.com/users/ravikumar1002", - html_url: "https://github.com/ravikumar1002", - followers_url: "https://api.github.com/users/ravikumar1002/followers", - following_url: "https://api.github.com/users/ravikumar1002/following{/other_user}", - gists_url: "https://api.github.com/users/ravikumar1002/gists{/gist_id}", - starred_url: "https://api.github.com/users/ravikumar1002/starred{/owner}{/repo}", - subscriptions_url: "https://api.github.com/users/ravikumar1002/subscriptions", - organizations_url: "https://api.github.com/users/ravikumar1002/orgs", - repos_url: "https://api.github.com/users/ravikumar1002/repos", - events_url: "https://api.github.com/users/ravikumar1002/events{/privacy}", - received_events_url: "https://api.github.com/users/ravikumar1002/received_events", - type: "User", - site_admin: false, - name: "Ravi kumar", - company: null, - blog: "https://ravikumar.dev/", - location: "Delhi, India", - email: null, - hireable: null, - bio: "Frontend developer", - twitter_username: "kumarravi1002", - public_repos: 47, - public_gists: 0, - followers: 9, - following: 13, - created_at: "2021-07-02T16:40:44Z", - updated_at: "2023-07-27T00:12:32Z", - }, - }, ]; }; diff --git a/test/fixtures/user/user.js b/test/fixtures/user/user.js index 7938c3271..e9746fd39 100644 --- a/test/fixtures/user/user.js +++ b/test/fixtures/user/user.js @@ -19,6 +19,7 @@ module.exports = () => { linkedin_id: "ankurnarkhede", github_id: githubUserInfo[0].username, github_display_name: githubUserInfo[0].displayName, + github_created_at: Number(new Date(githubUserInfo[0]._json.created_at).getTime()), isMember: true, phone: "1234567890", email: "abc@gmail.com", @@ -343,20 +344,5 @@ module.exports = () => { updated_at: Date.now(), created_at: Date.now(), }, - { - username: "ravikumar1002", - first_name: "ravi", - last_name: "kumar", - github_id: githubUserInfo[2].username, - github_display_name: githubUserInfo[2].displayName, - github_created_at: Number(new Date(githubUserInfo[2]._json.created_at).getTime()), - roles: { - member: false, - in_discord: true, - }, - incompleteUserDetails: false, - updated_at: Date.now(), - created_at: Date.now(), - }, ]; }; diff --git a/test/unit/models/users.test.js b/test/unit/models/users.test.js index cf2ce3e77..4fb868b21 100644 --- a/test/unit/models/users.test.js +++ b/test/unit/models/users.test.js @@ -104,9 +104,9 @@ describe("users", function () { }); it("It should have github_created_at fields", async function () { - const userData = userDataArray[15]; + const userData = userDataArray[0]; await users.addOrUpdate(userData); - const githubUsername = "ravikumar1002"; + const githubUsername = "ankur"; const { user } = await users.fetchUser({ githubUsername }); expect(user).to.haveOwnProperty("github_created_at"); });