Skip to content

Commit

Permalink
fixed cypress test not passing and added auth
Browse files Browse the repository at this point in the history
  • Loading branch information
elraphty committed Apr 21, 2024
1 parent 9ccc1d7 commit 719d8e2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ node_modules/
node_modules
yarn.lock

frontend/app/coverage
frontend/app/coverage
cypress/screenshots
4 changes: 1 addition & 3 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,8 @@ 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) {
token := r.Header.Get("token")

if IsFreePass() {
ctx := context.WithValue(r.Context(), ContextKey, token)
ctx := context.WithValue(r.Context(), ContextKey, "")
next.ServeHTTP(w, r.WithContext(ctx))
} else {
fmt.Println("Endpoint is for testing only : test endpoint")
Expand Down
36 changes: 16 additions & 20 deletions cypress/e2e/01_workspaces.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@ import { User, HostName, Workspaces } from '../support/objects/objects';

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

cy.request({
method: 'POST',
url: `${HostName}/workspaces/`,
headers: { 'x-jwt': `${ value }` },
headers: { 'x-jwt': `${value}` },
body: Workspaces[1]
});

cy.request({
method: 'POST',
url: `${HostName}/workspaces/`,
headers: { 'x-jwt': `${ value }` },
headers: { 'x-jwt': `${value}` },
body: Workspaces[2]
});
})
Expand All @@ -32,17 +31,16 @@ describe('Create Workspaces', () => {

describe('Edit Mission', () => {
it('passes', () => {
cy.upsertlogin(User).then(value =>
{
cy.upsertlogin(User).then(value => {
//Create 3 Workspaces
cy.request({
method: 'POST',
url: `${HostName}/workspaces/mission`,
headers: { 'x-jwt': `${ value }` },
body: {
headers: { 'x-jwt': `${value}` },
body: {
uuid: Workspaces[0].uuid,
mission: 'This is a sample mission for workspace'
}
}
}).then((resp) => {
expect(resp.status).to.eq(200)
})
Expand All @@ -53,17 +51,16 @@ describe('Edit Mission', () => {

describe('Edit Tactics', () => {
it('passes', () => {
cy.upsertlogin(User).then(value =>
{
cy.upsertlogin(User).then(value => {
//Create 3 Workspaces
cy.request({
method: 'POST',
url: `${HostName}/workspaces/tactics`,
headers: { 'x-jwt': `${ value }` },
body: {
headers: { 'x-jwt': `${value}` },
body: {
uuid: Workspaces[0].uuid,
mission: 'This is a sample tactics and objectives for workspace'
}
}
}).then((resp) => {
expect(resp.status).to.eq(200)
})
Expand All @@ -74,17 +71,16 @@ describe('Edit Tactics', () => {

describe('Edit Schematics Url', () => {
it('passes', () => {
cy.upsertlogin(User).then(value =>
{
cy.upsertlogin(User).then(value => {
//Create 3 Workspaces
cy.request({
method: 'POST',
url: `${HostName}/workspaces/schematicurl`,
headers: { 'x-jwt': `${ value }` },
body: {
headers: { 'x-jwt': `${value}` },
body: {
uuid: Workspaces[0].uuid,
mission: 'This is a sample schematic url for workspaces'
}
}
}).then((resp) => {
expect(resp.status).to.eq(200)
})
Expand Down
2 changes: 1 addition & 1 deletion routes/person.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func PersonRoutes() chi.Router {

r.Group(func(r chi.Router) {
r.Use(auth.CypressContext)
r.Post("/test", peopleHandler.UpsertLogin)
r.Post("/upsertlogin", peopleHandler.UpsertLogin)
})

r.Group(func(r chi.Router) {
Expand Down

0 comments on commit 719d8e2

Please sign in to comment.