Skip to content

Commit

Permalink
fix: do not update created at on edit bounty
Browse files Browse the repository at this point in the history
  • Loading branch information
Anish Yadav committed Feb 21, 2024
1 parent f247c84 commit 3cecdc0
Show file tree
Hide file tree
Showing 4 changed files with 313 additions and 7 deletions.
228 changes: 228 additions & 0 deletions frontend/app/yarn-error.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
Arguments:
/home/z0049w7n/.nvm/versions/node/v18.14.2/bin/node /home/z0049w7n/.cache/node/corepack/yarn/1.22.19/bin/yarn.js

PATH:
/home/z0049w7n/.nvm/versions/node/v18.14.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin:/home/z0049w7n/go/bin

Yarn version:
1.22.19

Node version:
18.14.2

Platform:
linux x64

Trace:
Error: getaddrinfo EAI_AGAIN registry.npmjs.org
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)

npm manifest:
{
"name": "catcher",
"version": "0.1.0",
"prettier": "prettier.json",
"private": true,
"scripts": {
"start": "craco start",
"start:tribes:docker": "PORT=23000 craco start",
"start:tribes:cluster": "PORT=13000 craco start",
"start:people": "PORT=3007 craco start",
"start:people:docker": "PORT=23007 craco start",
"start:people:cluster": "PORT=13007 craco start",
"build": "craco build",
"eject": "craco eject",
"lint": "eslint src --max-warnings 71 --ext .ts --ext .tsx --ignore-pattern *.spec.tsx --ignore-pattern *.spec.ts",
"lint:fix": "npm run lint -- --fix",
"prettier": "npx prettier --config .prettierrc.json -w ./src",
"prettier:check": "npx prettier --config .prettierrc.json --check ./src",
"prepare": "cd ../.. && husky install frontend/app/.husky",
"test": "yarn run test-jest",
"test-jest": "REACT_APP_IS_TEST=true NODE_ENV=test yarn jest --coverage --no-cache --transformIgnorePatterns \"./frontend/app/svg/\""
},
"dependencies": {
"@elastic/datemath": "^5.0.2",
"@elastic/eui": "^64.0.4",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@loomhq/loom-embed": "^1.4.0",
"@loomhq/record-sdk": "^2.35.16",
"@material/react-material-icon": "^0.15.0",
"@mui/base": "^5.0.0-beta.16",
"@mui/system": "^5.14.10",
"@types/date-fns": "^2.6.0",
"add": "^2.0.6",
"bootstrap": "^4.5.0",
"clsx": "^2.0.0",
"compose-function": "^3.0.3",
"date-fns": "^3.2.0",
"dateformat": "^3.0.3",
"formik": "^2.2.6",
"fuse.js": "^5.2.3",
"jest-fetch-mock": "^3.0.3",
"light-bolt11-decoder": "^3.0.0",
"lodash": "^4.17.15",
"memo-decorator": "^2.0.1",
"mobx": "^6.8.0",
"mobx-persist": "^0.4.1",
"mobx-persist-store": "^1.1.3",
"mobx-react-lite": "^3.4.3",
"moment": "^2.29.4",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-dropzone": "^14.2.3",
"react-intersection-observer": "^9.4.1",
"react-markdown": "^8.0.3",
"react-qr-svg": "^2.2.2",
"react-qrcode-logo": "^2.5.0",
"react-router-dom": "^5.2.0",
"react-scripts": "5.0.1",
"react-select": "^5.1.0",
"rehype-raw": "^6.1.1",
"remark-gfm": "^3.0.1",
"remark-rehype": "^10.1.0",
"socket.io-client": "^4.6.1",
"styled-components": "^5.1.0",
"yarn": "^1.22.19",
"yup": "^0.32.9"
},
"eslintConfig": {
"extends": [
"react-app",
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"root": true,
"rules": {
"arrow-body-style": [
"warn",
"as-needed"
],
"@typescript-eslint/typedef": [
"error",
{
"parameter": true,
"objectDestructuring": false,
"arrowParameter": true,
"memberVariableDeclaration": false
}
],
"no-use-before-define": [
"error",
{
"functions": true,
"classes": true,
"variables": true,
"allowNamedExports": false
}
],
"import/order": "error",
"camelcase": "off",
"comma-dangle": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": "warn",
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/ban-types": "warn",
"@typescript-eslint/ban-ts-comment": "warn",
"react-hooks/rules-of-hooks": "warn",
"react-hooks/exhaustive-deps": "warn",
"react/prop-types": "warn",
"no-unused-vars": "warn",
"no-var": "warn",
"no-extra-boolean-cast": "warn",
"no-useless-escape": "warn",
"no-prototype-builtins": "warn",
"no-empty-pattern": "warn",
"no-empty": "warn",
"no-multiple-empty-lines": "error",
"no-unreachable": "error",
"no-useless-catch": "warn",
"react/jsx-closing-bracket-location": [
"warn",
"tag-aligned"
],
"react/jsx-closing-tag-location": "warn",
"jsx-quotes": [
"error",
"prefer-double"
],
"prefer-const": "warn",
"no-const-assign": "warn",
"prefer-destructuring": [
"error",
{
"object": true,
"array": false
}
],
"prefer-template": "warn",
"func-style": "off",
"react/self-closing-comp": "warn",
"react/jsx-no-target-blank": "warn",
"react/jsx-key": "warn",
"react/no-children-prop": "warn",
"react/no-unescaped-entities": "warn",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"varsIgnorePattern": "_"
}
]
}
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@craco/craco": "^7.0.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.2",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^7.1.2",
"@types/dateformat": "^3.0.1",
"@types/jest": "^24.9.1",
"@types/node": "^12.12.27",
"@types/react-dom": "18.0.4",
"@types/react-router-dom": "^5.1.8",
"@types/sinon": "^17.0.2",
"@types/styled-components": "^5.1.0",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"bootstrap": "^4.5.0",
"eslint": "^8.37.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-react": "^1.1.7",
"eslint-plugin-react": "^7.31.10",
"husky": "^8.0.3",
"nock": "^13.3.0",
"prettier": "3.0.3",
"react-error-overlay": "6.0.9",
"sinon": "^17.0.1",
"ts-jest": "^29.1.1",
"ts-loader": "^9.5.1",
"typescript": "^5.3.2"
}
}

yarn manifest:
No manifest

Lockfile:
No lockfile
15 changes: 8 additions & 7 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import (
)

type bountyHandler struct {
httpClient HttpClient
db db.Database
httpClient HttpClient
db db.Database
generateBountyResponse func(bounties []db.Bounty) []db.BountyResponse
}

func NewBountyHandler(httpClient HttpClient, db db.Database) *bountyHandler {
return &bountyHandler{
httpClient: httpClient,
db: db,
httpClient: httpClient,
db: db,
generateBountyResponse: GenerateBountyResponse,
}
}
Expand Down Expand Up @@ -188,9 +188,6 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques

//Check if bounty exists
bounty.Updated = &now
if bounty.Created == 0 {
bounty.Created = time.Now().Unix()
}

if bounty.Type == "" {
w.WriteHeader(http.StatusBadRequest)
Expand Down Expand Up @@ -227,6 +224,10 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques
h.db.UpdateBountyNullColumn(bounty, "assignee")
}

if bounty.ID == 0 && bounty.Created == 0 {
bounty.Created = time.Now().Unix()
}

if bounty.Title != "" && bounty.ID != 0 {
// get bounty from DB
dbBounty := h.db.GetBounty(bounty.ID)
Expand Down
42 changes: 42 additions & 0 deletions handlers/bounty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http/httptest"
"strings"
"testing"
"time"

"github.com/go-chi/chi"
"github.com/stakwork/sphinx-tribes/auth"
Expand Down Expand Up @@ -191,6 +192,47 @@ func TestCreateOrEditBounty(t *testing.T) {
mockDb.AssertExpectations(t)
})

t.Run("should not update created at when bounty is updated", func(t *testing.T) {
rr := httptest.NewRecorder()
handler := http.HandlerFunc(bHandler.CreateOrEditBounty)
now := time.Now().UnixMilli()
mockOrg := db.Organization{
ID: 1,
Uuid: "org-1",
Name: "custom org",
OwnerPubKey: "org-key",
}
existingBounty := db.Bounty{
ID: 1,
Type: "coding",
Title: "first bounty",
Description: "first bounty description",
OrgUuid: "org-1",
OwnerID: "second-user",
Created: now,
}
updatedBounty := existingBounty
updatedBounty.Title = "first bounty updated"
mockDb.On("UpdateBountyBoolColumn", mock.AnythingOfType("db.Bounty"), "show").Return(existingBounty)
mockDb.On("UpdateBountyNullColumn", mock.AnythingOfType("db.Bounty"), "assignee").Return(existingBounty)
mockDb.On("GetBounty", uint(1)).Return(existingBounty).Once()
mockDb.On("UserHasManageBountyRoles", "test-key", mockOrg.Uuid).Return(true).Once()
mockDb.On("CreateOrEditBounty", mock.MatchedBy(func(b db.Bounty) bool {
return b.Created == now && b.Updated.UnixMilli() != now
})).Return(updatedBounty, nil).Once()

body, _ := json.Marshal(updatedBounty)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, "/", bytes.NewReader(body))
if err != nil {
t.Fatal(err)
}

handler.ServeHTTP(rr, req)

assert.Equal(t, http.StatusOK, rr.Code)
mockDb.AssertExpectations(t)
})

t.Run("should return error if failed to add new bounty", func(t *testing.T) {
rr := httptest.NewRecorder()
handler := http.HandlerFunc(bHandler.CreateOrEditBounty)
Expand Down
35 changes: 35 additions & 0 deletions out.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
DatePosted,Organization,BountyAmount,Provider,Hunter,BountyTitle,BountyLink,BountyStatus,DateAssigned,DatePaid
2024-01-07 18:12:36 +0530 IST,Guardians,1000000,Evan,Evan,Test Bounty ,https://community.sphinx.chat/bounty/1,Assigned,2024-01-07 19:10:11.410492 +0530 IST,<nil>
2024-01-06 04:04:03 +0530 IST,,100000,,,Hunter Referral Bonus,https://community.sphinx.chat/bounty/1086,Assigned,<nil>,<nil>
2024-01-05 23:53:05 +0530 IST,,300000,,,Make Admin Metrics Page Responsive On All Screens,https://community.sphinx.chat/bounty/1081,Assigned,<nil>,<nil>
2024-01-05 17:52:19 +0530 IST,,150000,,,Add loading state when changing display,https://community.sphinx.chat/bounty/1077,Assigned,<nil>,<nil>
2024-01-04 23:12:32 +0530 IST,,200000,,,Admin is not showing the hunter/provider alias of the sphinx profiles,https://community.sphinx.chat/bounty/1068,Assigned,<nil>,<nil>
2024-01-03 23:50:58 +0530 IST,,100000,,,Refer a hunter to the bounties platform,https://community.sphinx.chat/bounty/1055,Assigned,<nil>,<nil>
2024-01-03 21:57:35 +0530 IST,,300000,,,Create component test for OrganizationView,https://community.sphinx.chat/bounty/1049,Assigned,<nil>,<nil>
2024-01-03 14:57:50 +0530 IST,,600000,,,[Date Range] Implement custom time filters,https://community.sphinx.chat/bounty/1042,Assigned,<nil>,<nil>
2024-01-02 23:28:25 +0530 IST,,300000,,,Hide tribe button if no tribe is attached to a bounty ,https://community.sphinx.chat/bounty/1035,Assigned,<nil>,<nil>
2024-01-02 23:25:45 +0530 IST,,200000,,,Create unit test for people.ts,https://community.sphinx.chat/bounty/1034,Assigned,<nil>,<nil>
2024-01-02 23:24:17 +0530 IST,,400000,,,Add ability to manually enlarge the height of the description box when creating bounty,https://community.sphinx.chat/bounty/1033,Assigned,<nil>,<nil>
2023-12-27 17:46:08 +0530 IST,,400000,,,Create error notification if bounty fails to get created,https://community.sphinx.chat/bounty/1016,Assigned,<nil>,<nil>
2023-12-22 17:28:39 +0530 IST,,150000,,,Remove details section for person node,https://community.sphinx.chat/bounty/967,Assigned,<nil>,<nil>
2023-12-21 16:28:06 +0530 IST,,250000,,,Get video IDs inside Jarvis and check for duplicates,https://community.sphinx.chat/bounty/963,Assigned,<nil>,<nil>
2023-12-09 02:11:18 +0530 IST,,50000,,,Unable to upload a picture to an organization even with right permissions,https://community.sphinx.chat/bounty/875,Assigned,<nil>,<nil>
2023-12-08 22:55:40 +0530 IST,,300000,,,Display new UI for Clips from an Episode view in details section,https://community.sphinx.chat/bounty/874,Assigned,<nil>,<nil>
2023-12-08 01:32:34 +0530 IST,,700000,,,"Create ""Add secondbrain flow""",https://community.sphinx.chat/bounty/870,Assigned,<nil>,<nil>
2023-12-01 00:34:59 +0530 IST,,1050000,,,Consultation for implementing a full testing suite,https://community.sphinx.chat/bounty/819,Assigned,<nil>,<nil>
2023-11-28 19:28:36 +0530 IST,,400000,,,Transaction List Improvement,https://community.sphinx.chat/bounty/804,Assigned,<nil>,<nil>
2023-11-23 16:47:40 +0530 IST,,250000,,,Store default graph view in local storage,https://community.sphinx.chat/bounty/776,Assigned,<nil>,<nil>
2023-11-17 02:12:24 +0530 IST,,600000,,,Prevent jitsi recordings from stopping after 10 minutes,https://community.sphinx.chat/bounty/375,Assigned,<nil>,<nil>
2023-11-03 22:55:26 +0530 IST,,6500000,,,Implement Bitcoin Script interpreter,https://community.sphinx.chat/bounty/650,Assigned,<nil>,<nil>
2023-11-03 00:12:45 +0530 IST,,200000,,,Add coverage for component testing,https://community.sphinx.chat/bounty/630,Assigned,<nil>,<nil>
2023-11-02 21:00:16 +0530 IST,,1000000,,,Embed Jitsi into Mac desktop app,https://community.sphinx.chat/bounty/386,Assigned,<nil>,<nil>
2023-10-11 04:06:52 +0530 IST,,145678,,,Design 3 logos and a color palette,https://community.sphinx.chat/bounty/532,Assigned,<nil>,<nil>
2023-10-06 05:24:36 +0530 IST,,400000,,,[NOSTR] Configure NOSTR node for support channel and website chat widget,https://community.sphinx.chat/bounty/510,Assigned,<nil>,<nil>
2023-10-03 22:58:44 +0530 IST,,500000,,,Implement Script to Download Loom Videos,https://community.sphinx.chat/bounty/482,Assigned,<nil>,<nil>
2023-09-30 03:27:22 +0530 IST,,500000,,,Graphics Artist for Postcard,https://community.sphinx.chat/bounty/468,Assigned,<nil>,<nil>
2023-09-14 22:12:11 +0530 IST,,750000,,,Fix Jitsi - one way audio issues,https://community.sphinx.chat/bounty/387,Assigned,<nil>,<nil>
2023-06-10 00:44:18 +0530 IST,,500000,,,Write a Neo4j query that can search multiple words in a graph,https://community.sphinx.chat/bounty/177,Assigned,<nil>,<nil>
2023-06-04 10:30:30 +0530 IST,,1250000,,,Affinity integration,https://community.sphinx.chat/bounty/278,Assigned,<nil>,<nil>
2023-03-24 20:52:33 +0530 IST,,200000,,,Channel opening docs improvement,https://community.sphinx.chat/bounty/51,Assigned,<nil>,<nil>
2023-02-17 05:01:00 +0530 IST,,800000,,,Speaker Matching Model,https://community.sphinx.chat/bounty/108,Assigned,<nil>,<nil>
2023-02-17 04:48:49 +0530 IST,,800000,,,Dockerize Python Library,https://community.sphinx.chat/bounty/259,Assigned,<nil>,<nil>

0 comments on commit 3cecdc0

Please sign in to comment.