Skip to content

Commit

Permalink
Merge pull request #1628 from stakwork/feature-add-features-endpoints
Browse files Browse the repository at this point in the history
Feature add features endpoints
  • Loading branch information
elraphty authored May 1, 2024
2 parents a341797 + 1087588 commit fe70a56
Show file tree
Hide file tree
Showing 23 changed files with 2,607 additions and 45 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ notes.md
frontend/packrd/packed-packr.go
.idea/
node_modules/
node_modules
yarn.lock

frontend/app/coverage
frontend/app/coverage
cypress/screenshots
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "chrome",
"request": "attach",
"name": "Attach to Chrome",
"port": 9222,
"urlFilter": "http://localhost:4200/*",
"webRoot": "${workspaceFolder}",
"configurations": [

]
}
14 changes: 14 additions & 0 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ func ConnectionCodeContext(next http.Handler) http.Handler {
})
}

// CypressContext allows testing for cypress
func CypressContext(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if IsFreePass() {
ctx := context.WithValue(r.Context(), ContextKey, "")
next.ServeHTTP(w, r.WithContext(ctx))
} else {
fmt.Println("Endpoint is for testing only : test endpoint")
http.Error(w, http.StatusText(401), 401)
return
}
})
}

func AdminCheck(pubkey string) bool {
for _, val := range config.SuperAdmins {
if val == pubkey {
Expand Down
9 changes: 9 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
8 changes: 8 additions & 0 deletions cypress/e2e/00_create_user.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { User } from '../support/objects/objects'

describe('Create User', () => {
it('it creates a user', () => {
const response = cy.upsertlogin(User);
return response;
})
});
101 changes: 101 additions & 0 deletions cypress/e2e/01_workspaces.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { User, HostName, Workspaces } from '../support/objects/objects';


describe('Create Workspaces', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
for(let i = 0; i <= 2; i++) {
cy.request({
method: 'POST',
url: `${HostName}/workspaces/`,
headers: { 'x-jwt': `${value}` },
body: Workspaces[i]
}).its('body').should('have.property', 'name', Workspaces[i].name.trim());
}
})
})
})

describe('Edit Mission', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
for(let i = 0; i <= 2; i++) {
cy.request({
method: 'POST',
url: `${HostName}/workspaces/mission`,
headers: { 'x-jwt': `${value}` },
body: {
uuid: Workspaces[i].uuid,
owner_pubkey: Workspaces[i].owner_pubkey,
mission: Workspaces[i].mission + '_addedtext'
}
}).then((resp) => {
expect(resp.status).to.eq(200)
})
}
})
})
})

describe('Edit Tactics', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
for(let i = 0; i <= 2; i++) {
cy.request({
method: 'POST',
url: `${HostName}/workspaces/tactics`,
headers: { 'x-jwt': `${value}` },
body: {
uuid: Workspaces[i].uuid,
owner_pubkey: Workspaces[i].owner_pubkey,
tactics: Workspaces[i].tactics + '_addedtext'
}
}).then((resp) => {
expect(resp.status).to.eq(200)
})
}
})
})
})

describe('Edit Schematics Url', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
for(let i = 0; i <= 2; i++) {
cy.request({
method: 'POST',
url: `${HostName}/workspaces/schematicurl`,
headers: { 'x-jwt': `${value}` },
body: {
uuid: Workspaces[i].uuid,
owner_pubkey: Workspaces[i].owner_pubkey,
schematic_url: Workspaces[i].schematic_url + '_addedtext'
}
}).then((resp) => {
expect(resp.status).to.eq(200)
})
}
})
})
})


describe('Check Workspace Values', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
for(let i = 0; i <= 2; i++) {
cy.request({
method: 'GET',
url: `${HostName}/workspaces/` + Workspaces[i].uuid,
headers: { 'x-jwt': `${ value }` },
body: {}
}).then((resp) => {
expect(resp.status).to.eq(200)
expect(resp.body).to.have.property('mission', Workspaces[i].mission.trim() + '_addedtext')
expect(resp.body).to.have.property('tactics', Workspaces[i].tactics.trim() + '_addedtext')
expect(resp.body).to.have.property('schematic_url', Workspaces[i].schematic_url.trim() + '_addedtext')
})
}
})
})
})
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
36 changes: 36 additions & 0 deletions cypress/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
declare namespace Cypress {
interface Chainable {
upsertlogin(person: Person): Promise<string>;
}

type RandomObject = { [key: string]: string };

type LoginResponse = {
jwt: string;
//user: Person;
}

type Person = {
id?: number;
uuid?: string;
owner_pubkey: string;
owner_alias: string;
unique_name: string;
description: string;
tags: String[]
img: string;
created?: number;
updated?: string;
unlisted: boolean;
deleted: boolean;
last_login?: number;
owner_route_hint: string;
owner_contact_key: string;
price_to_meet: number;
new_ticket_time?: number;
twitter_confirmed: boolean;
referred_by: number;
extras: RandomObject;
github_issues: RandomObject;
}
}
13 changes: 13 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = (on, config) => {

on('before:browser:launch', (browser = {}, args) => {

if (browser.name === 'chrome') {
args.push('--remote-debugging-port=9222')

// whatever you return here becomes the new args
return args
}

})
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import dotenv from 'dotenv';
dotenv.config();

import { HostName } from './objects/objects';

// @ts-check
// @ts-check
/// <reference types="cypress" />

Cypress.Commands.add('upsertlogin', (person: Cypress.Person) => {
cy.request({
method: 'POST',
url: `http://${HostName}/person/upsertlogin`,
headers: {},
body: person
}).then((response) => response.body);
});
20 changes: 20 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading

0 comments on commit fe70a56

Please sign in to comment.