Skip to content

Commit

Permalink
fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
elraphty committed May 20, 2024
2 parents 3b00e29 + b68e494 commit cb078e9
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 75 deletions.
113 changes: 102 additions & 11 deletions cypress/e2e/02_repositories.cy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { User, HostName, Workspaces, Repositories } from '../support/objects/objects';
import { User, HostName, Repositories } from '../support/objects/objects';


describe('Create Repositories for Workspace', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
for(let i = 0; i <= 1; i++) {
for (let i = 0; i <= 1; i++) {
cy.request({
method: 'POST',
url: `${HostName}/workspaces/repositories`,
Expand All @@ -13,28 +13,119 @@ describe('Create Repositories for Workspace', () => {
}).its('body').then(body => {
expect(body).to.have.property('name').and.equal(Repositories[i].name.trim());
expect(body).to.have.property('url').and.equal(Repositories[i].url.trim());
});
});
}
})
})
})

describe('Modify Repository name for Workspace', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
for (let i = 0; i <= 1; i++) {
cy.request({
method: 'POST',
url: `${HostName}/workspaces/repositories`,
headers: { 'x-jwt': `${value}` },
body: {
uuid: Repositories[i].uuid,
name: Repositories[i].name.trim() + "_addText"
}
}).its('body').then(body => {
expect(body).to.have.property('name').and.equal(Repositories[i].name.trim() + "_addText");
expect(body).to.have.property('url').and.equal(Repositories[i].url.trim());
});
}
})
})
})

describe('Modify Repository url for Workspace', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
for (let i = 0; i <= 1; i++) {
cy.request({
method: 'POST',
url: `${HostName}/workspaces/repositories`,
headers: { 'x-jwt': `${value}` },
body: {
uuid: Repositories[i].uuid,
url: Repositories[i].url.trim() + "_addText"
}
}).its('body').then(body => {
expect(body).to.have.property('name').and.equal(Repositories[i].name.trim() + "_addText");
expect(body).to.have.property('url').and.equal(Repositories[i].url.trim() + "_addText");
});
}
})
})
})


describe('Check Repositories Values', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
for (let i = 0; i <= 1; i++) {
cy.request({
method: 'GET',
url: `${HostName}/workspaces/repositories/` + Repositories[i].workspace_uuid,
headers: { 'x-jwt': `${value}` },
body: {}
}).then((resp) => {
expect(resp.status).to.eq(200)
expect(resp.body[i]).to.have.property('name', Repositories[i].name.trim() + "_addText")
expect(resp.body[i]).to.have.property('url', Repositories[i].url.trim() + "_addText")
})
}
})
})
})

describe('Get repository by uuid', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
for (let i = 0; i <= 1; i++) {
cy.request({
method: 'GET',
url: `${HostName}/workspaces/${Repositories[i].workspace_uuid}/repository/${Repositories[i].uuid}`,
headers: { 'x-jwt': `${value}` }
}).then((resp) => {
expect(resp.status).to.eq(200)
expect(resp.body).to.have.property('name', Repositories[i].name.trim() + "_addText")
expect(resp.body).to.have.property('url', Repositories[i].url.trim() + "_addText")
})
}
})
})
})

describe('Delete repository by uuid', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
cy.request({
method: 'GET',
url: `${HostName}/workspaces/repositories/` + Repositories[0].workspace_uuid,
headers: { 'x-jwt': `${ value }` },
body: {}
method: 'DELETE',
url: `${HostName}/workspaces/${Repositories[0].workspace_uuid}/repository/${Repositories[0].uuid}`,
headers: { 'x-jwt': `${value}` },
body: {}
}).then((resp) => {
expect(resp.status).to.eq(200)
expect(resp.body[0]).to.have.property('name', Repositories[0].name.trim())
expect(resp.body[0]).to.have.property('url', Repositories[0].url.trim())
expect(resp.body[1]).to.have.property('name', Repositories[1].name.trim())
expect(resp.body[1]).to.have.property('url', Repositories[1].url.trim())
})
})
})
})

describe('Check delete by uuid', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
cy.request({
method: 'GET',
url: `${HostName}/workspaces/${Repositories[0].workspace_uuid}/repository/${Repositories[0].uuid}`,
headers: { 'x-jwt': `${value}` },
body: {},
failOnStatusCode: false
}).then((resp) => {
expect(resp.status).to.eq(404);
})
})
})
})
21 changes: 21 additions & 0 deletions cypress/e2e/07_add_bounty_to_phase.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { User, HostName, Bounties } from '../support/objects/objects';


describe('Create Bounty', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
for (let i = 0; i <= 2; i++) {
cy.request({
method: 'POST',
url: `${HostName}/gobounties/`,
headers: { 'x-jwt': `${value}` },
body: Bounties[i],
failOnStatusCode: false
})//.its('body').should('have.property', 'id', Workspaces[i].name.trim())
.then(value => {
console.log(value);
});
}
})
})
})
37 changes: 36 additions & 1 deletion cypress/support/objects/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,39 @@ export const Phases = [
{ uuid: 'com1msgn1e4a0ts5kls0', feature_uuid: 'com1kson1e49th88dbg0', name: ' MVP ', priority: 0 },
{ uuid: 'com1mvgn1e4a1879uiv0', feature_uuid: 'com1kson1e49th88dbg0', name: ' Phase 2 ', priority: 1 },
{ uuid: 'com1n2gn1e4a1i8p60p0', feature_uuid: 'com1kson1e49th88dbg0', name: ' Phase 3 ', priority: 2 },
];
];

export const Bounties = [
{
id: 0,
owner_id: '',
paid: false,
show: true,
completed: false,
type: '', //TODO find out more
award: '', //TODO find out more
assigned_hours: 2,
bounty_expires: '',
commitment_fee: 0, //TODO find out more
price: 21,
title: 'Add Features endpoints',
tribe: '',
assignee: '',
ticket_url: '',
workspace_id: Workspaces[0],
description: '',
wanted_type: '', //TODO find out more
deliverables: '', //TODO find out more
github_description: '',
one_sentence_summary: '',
estimated_session_length: '', //TODO find out more
estimated_completion_date: '2024-05-31',
created: '',
updated: '',
assigned_date: '',
completion_date: '',
mark_as_paid_date: '',
paid_date: '',
coding_languages: ['Golang'],
},
]
4 changes: 3 additions & 1 deletion db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ type Database interface {
PersonUniqueNameFromName(name string) (string, error)
ProcessAlerts(p Person)
UserHasAccess(pubKeyFromAuth string, uuid string, role string) bool
CreateWorkspaceRepository(m WorkspaceRepositories) (WorkspaceRepositories, error)
CreateOrEditWorkspaceRepository(m WorkspaceRepositories) (WorkspaceRepositories, error)
GetWorkspaceRepositorByWorkspaceUuid(uuid string) []WorkspaceRepositories
GetWorkspaceRepoByWorkspaceUuidAndRepoUuid(workspace_uuid string, uuid string) (WorkspaceRepositories, error)
DeleteWorkspaceRepository(workspace_uuid string, uuid string) bool
CreateOrEditFeature(m WorkspaceFeatures) (WorkspaceFeatures, error)
GetFeaturesByWorkspaceUuid(uuid string, r *http.Request) []WorkspaceFeatures
GetWorkspaceFeaturesCount(uuid string) int64
Expand Down
1 change: 1 addition & 0 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ type WorkspaceFeatures struct {
Brief string `json:"brief"`
Requirements string `json:"requirements"`
Architecture string `json:"architecture"`
Url string `json:"url"`
Created *time.Time `json:"created"`
Updated *time.Time `json:"updated"`
CreatedBy string `json:"created_by"`
Expand Down
20 changes: 19 additions & 1 deletion db/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (db database) CreateOrEditWorkspace(m Workspace) (Workspace, error) {
return m, nil
}

func (db database) CreateWorkspaceRepository(m WorkspaceRepositories) (WorkspaceRepositories, error) {
func (db database) CreateOrEditWorkspaceRepository(m WorkspaceRepositories) (WorkspaceRepositories, error) {
m.Name = strings.TrimSpace(m.Name)
m.Url = strings.TrimSpace(m.Url)

Expand All @@ -70,6 +70,8 @@ func (db database) CreateWorkspaceRepository(m WorkspaceRepositories) (Workspace
db.db.Create(&m)
}

db.db.Model(&WorkspaceRepositories{}).Where("uuid = ?", m.Uuid).Find(&m)

return m, nil
}

Expand All @@ -81,6 +83,22 @@ func (db database) GetWorkspaceRepositorByWorkspaceUuid(uuid string) []Workspace
return ms
}

func (db database) GetWorkspaceRepoByWorkspaceUuidAndRepoUuid(workspace_uuid string, uuid string) (WorkspaceRepositories, error) {
var ms WorkspaceRepositories

result := db.db.Model(&WorkspaceRepositories{}).Where("workspace_uuid = ?", workspace_uuid).Where("uuid = ?", uuid).Find(&ms)
if result.RowsAffected == 0 {
return ms, fmt.Errorf("workspace repository not found")
}

return ms, nil
}

func (db database) DeleteWorkspaceRepository(workspace_uuid string, uuid string) bool {
db.db.Where("workspace_uuid = ?", workspace_uuid).Where("uuid = ?", uuid).Delete(&WorkspaceRepositories{})
return true
}

func (db database) GetWorkspaceUsers(uuid string) ([]WorkspaceUsersData, error) {
ms := []WorkspaceUsersData{}

Expand Down
54 changes: 50 additions & 4 deletions handlers/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ func (oh *workspaceHandler) UpdateWorkspace(w http.ResponseWriter, r *http.Reque
json.NewEncoder(w).Encode(p)
}

func (oh *workspaceHandler) CreateWorkspaceRepository(w http.ResponseWriter, r *http.Request) {
func (oh *workspaceHandler) CreateOrEditWorkspaceRepository(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
if pubKeyFromAuth == "" {
Expand All @@ -803,7 +803,12 @@ func (oh *workspaceHandler) CreateWorkspaceRepository(w http.ResponseWriter, r *
return
}

workspaceRepo.CreatedBy = pubKeyFromAuth
if len(workspaceRepo.Uuid) == 0 {
workspaceRepo.Uuid = xid.New().String()
workspaceRepo.CreatedBy = pubKeyFromAuth
}

workspaceRepo.UpdatedBy = pubKeyFromAuth

if workspaceRepo.Uuid == "" {
workspaceRepo.Uuid = xid.New().String()
Expand All @@ -828,7 +833,7 @@ func (oh *workspaceHandler) CreateWorkspaceRepository(w http.ResponseWriter, r *
return
}

p, err := oh.db.CreateWorkspaceRepository(workspaceRepo)
p, err := oh.db.CreateOrEditWorkspaceRepository(workspaceRepo)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
Expand All @@ -854,8 +859,49 @@ func (oh *workspaceHandler) GetWorkspaceRepositorByWorkspaceUuid(w http.Response
json.NewEncoder(w).Encode(workspaceFeatures)
}

// New method for getting features by workspace uuid
func (oh *workspaceHandler) GetWorkspaceRepoByWorkspaceUuidAndRepoUuid(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
if pubKeyFromAuth == "" {
fmt.Println("no pubkey from auth")
w.WriteHeader(http.StatusUnauthorized)
return
}

workspace_uuid := chi.URLParam(r, "workspace_uuid")
uuid := chi.URLParam(r, "uuid")
WorkspaceRepository, err := oh.db.GetWorkspaceRepoByWorkspaceUuidAndRepoUuid(workspace_uuid, uuid)
if err != nil {
fmt.Println("workspace repository not found:", err)
w.WriteHeader(http.StatusNotFound)
json.NewEncoder(w).Encode(map[string]string{"error": "Repository not found"})
return
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(WorkspaceRepository)
}

func (oh *workspaceHandler) DeleteWorkspaceRepository(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)

if pubKeyFromAuth == "" {
fmt.Println("no pubkey from auth")
w.WriteHeader(http.StatusUnauthorized)
return
}

workspace_uuid := chi.URLParam(r, "workspace_uuid")
uuid := chi.URLParam(r, "uuid")

oh.db.DeleteWorkspaceRepository(workspace_uuid, uuid)

w.WriteHeader(http.StatusOK)
}

// New method for getting features by workspace uuid
func (oh *workspaceHandler) GetFeaturesByWorkspaceUuid(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
Expand Down
Loading

0 comments on commit cb078e9

Please sign in to comment.