Skip to content

Commit

Permalink
Merge pull request #342 from developmentseed/add/team-list-pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeorge authored Dec 15, 2022
2 parents 9cc5fd1 + 7c8b17d commit 2f72db7
Show file tree
Hide file tree
Showing 36 changed files with 747 additions and 229 deletions.
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ NEXTAUTH_URL=http://127.0.0.1:3000
NEXTAUTH_SECRET=next-auth-cypress-secret
DATABASE_URL=postgres://postgres:postgres@localhost:5434/osm-teams-test
TESTING=true
LOG_LEVEL=silent
13 changes: 0 additions & 13 deletions app/manage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const {
removeOwner,
addManager,
removeManager,
createOrgTeam,
getOrgTeams,
getOrgMembers,
listMyOrgs,
getOrgStaff,
Expand Down Expand Up @@ -160,17 +158,6 @@ function manageRouter(handler) {
removeManager
)

handler.post(
'/api/organizations/:id/teams',
can('organization:create-team'),
createOrgTeam
)
handler.get(
'/api/organizations/:id/teams',
can('organization:view-members'),
getOrgTeams
)

/**
* Manage organization badges
*/
Expand Down
35 changes: 0 additions & 35 deletions app/manage/organizations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const organization = require('../../src/models/organization')
const team = require('../../src/models/team')
const { teamsMembersModeratorsHelper } = require('./utils')
const { map, prop } = require('ramda')
const Boom = require('@hapi/boom')

Expand Down Expand Up @@ -237,38 +236,6 @@ async function removeManager(req, reply) {
}
}

/**
* Create org team
*/
async function createOrgTeam(req, reply) {
const { id } = req.params
const { body } = req
const { user_id } = req.session

try {
const data = await organization.createOrgTeam(id, body, user_id)
reply.send(data)
} catch (err) {
console.log(err)
throw Boom.badRequest(err.message)
}
}

/**
* List org teams
*/
async function getOrgTeams(req, reply) {
const { id } = req.params
try {
const data = await team.list({ organizationId: id })
const enhancedData = await teamsMembersModeratorsHelper(data)
reply.send(enhancedData)
} catch (err) {
console.log(err)
throw Boom.badRequest(err.message)
}
}

module.exports = {
createOrg,
getOrg,
Expand All @@ -278,8 +245,6 @@ module.exports = {
removeOwner,
addManager,
removeManager,
createOrgTeam,
getOrgTeams,
listMyOrgs,
getOrgStaff,
getOrgMembers,
Expand Down
18 changes: 0 additions & 18 deletions app/manage/permissions/create-org-team.js

This file was deleted.

1 change: 0 additions & 1 deletion app/manage/permissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const teamPermissions = {

const organizationPermissions = {
'organization:edit': require('./edit-org'),
'organization:create-team': require('./create-org-team'),
'organization:member': require('./member-org'),
'organization:view-members': require('./view-org-members'),
'organization:view-team-keys': require('./view-org-team-keys'),
Expand Down
2 changes: 1 addition & 1 deletion app/manage/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function listTeams(req, reply) {
async function listMyTeams(req, reply) {
const { user_id: osmId } = req.session
try {
const memberOfTeams = await team.list({ osmId })
const memberOfTeams = await team.list({ osmId, disableLimit: true })
const moderatorOfTeams = await team.listModeratedBy(osmId)
const result = {
osmId,
Expand Down
31 changes: 13 additions & 18 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,20 @@ module.exports = defineConfig({
return null
},
'db:seed': async () => {
// Add teams
await Promise.all(
[
[
{
name: 'Team 1',
},
user1.id,
],
[
{
name: 'Team 2',
privacy: 'private',
},
user1.id,
],
].map((args) => Team.create(...args))
// Add teams in series
await Team.create(
{
name: 'Team 1',
},
user1.id
)
await Team.create(
{
name: 'Team 2',
privacy: 'private',
},
user1.id
)

return null
},
'db:seed:team-invitations': async (teamInvitations) => {
Expand Down
59 changes: 52 additions & 7 deletions cypress/e2e/organizations.cy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { generateSequenceArray } = require('../../src/lib/utils')

const user1 = {
id: 1,
display_name: 'User 1',
Expand All @@ -9,32 +11,75 @@ const org1 = {
ownerId: user1.id,
}

const team1 = {
name: 'Team 1',
}
const ORG_TEAMS_COUNT = 35

const teams = generateSequenceArray(ORG_TEAMS_COUNT, 1).map((i) => ({
id: i,
name: `Team ${i}`,
}))

describe('Organization page', () => {
before(() => {
cy.task('db:reset')
cy.task('db:seed:organizations', [org1])
})

it('List organization teams', () => {
it('Display message when organization has no teams', () => {
cy.login(user1)

// Check state when no teams are available
cy.visit('/organizations/1')
cy.get('body').should('contain', 'This organization has no teams.')
cy.get('[data-cy=org-teams-table]').contains(
'This organization has no teams'
)
cy.get('[data-cy=org-teams-table-pagination]').should('not.exist')
})

it('Display paginated list of teams', () => {
cy.login(user1)

// Seed org teams
cy.task('db:seed:organization-teams', {
orgId: org1.id,
teams: [team1],
teams,
managerId: user1.id,
})

// Check state when teams are available
cy.visit('/organizations/1')
cy.get('body').should('contain', team1.name)

cy.get('[data-cy=org-teams-table]').contains('Team 10')

// Click last page button
cy.get('[data-cy=org-teams-table-pagination]').within(() => {
cy.get('[data-cy=last-page-button]').click()
})

// Last item is present
cy.get('[data-cy=org-teams-table]').contains('Team 9')

// Click page 2 button
cy.get('[data-cy=org-teams-table-pagination]').within(() => {
cy.get('[data-cy=page-2-button]').click()
})

// Item from page 2 is present
cy.get('[data-cy=org-teams-table]').contains('Team 2')

// Click next page button
cy.get('[data-cy=org-teams-table-pagination]').within(() => {
cy.get('[data-cy=next-page-button]').click()
})

// Item from page 3 is present
cy.get('[data-cy=org-teams-table]').contains('Team 3')

// Click previous page button
cy.get('[data-cy=org-teams-table-pagination]').within(() => {
cy.get('[data-cy=previous-page-button]').click()
})

// Item from page 2 is present
cy.get('[data-cy=org-teams-table]').contains('Team 2')
})
})
4 changes: 2 additions & 2 deletions next-swagger-doc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"apiFolder": "src/pages/api",
"apiFolder": "src",
"schemaFolders": [
"models"
"src"
],
"definition": {
"openapi": "3.0.0",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"license": "MIT",
"scripts": {
"docs:update-version": "node -p \"JSON.stringify({'apiFolder': 'src/pages/api','schemaFolders': ['models'],'definition': {'openapi': '3.0.0','info': {'title': 'OSM Teams API Docs','version': require('./package.json').version}}}, null, 2)\" > next-swagger-doc.json",
"docs:update-version": "node -p \"JSON.stringify({'apiFolder': 'src','schemaFolders': ['src'],'definition': {'openapi': '3.0.0','info': {'title': 'OSM Teams API Docs','version': require('./package.json').version}}}, null, 2)\" > next-swagger-doc.json",
"docs:generate": "yarn next-swagger-doc-cli next-swagger-doc.json",
"docs:validate": "yarn docs:update-version && yarn docs:generate && swagger-cli validate public/swagger.json",
"cy:open": "cypress open",
Expand Down Expand Up @@ -77,6 +77,7 @@
"pg": "^8.7.1",
"pino": "^5.17.0",
"pino-pretty": "^2.5.0",
"prop-types": "^15.8.1",
"qs": "^6.10.3",
"querystring": "^0.2.1",
"ramda": "^0.26.1",
Expand Down
5 changes: 5 additions & 0 deletions public/static/icon-chevron-left--small.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions public/static/icon-chevron-left--trail.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions public/static/icon-chevron-right--small.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions public/static/icon-chevron-right--trail.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2f72db7

Please sign in to comment.