|
| 1 | +describe('Team API tests', () => { |
| 2 | + Cypress.session.clearAllSavedSessions(); |
| 3 | + |
| 4 | + let teamId; |
| 5 | + let userId; |
| 6 | + |
| 7 | + before(() => { |
| 8 | + cy.login(Cypress.env('umami_user'), Cypress.env('umami_password')); |
| 9 | + cy.fixture('users').then(data => { |
| 10 | + const userCreate = data.userCreate; |
| 11 | + cy.request({ |
| 12 | + method: 'POST', |
| 13 | + url: '/api/users', |
| 14 | + headers: { |
| 15 | + 'Content-Type': 'application/json', |
| 16 | + Authorization: Cypress.env('authorization'), |
| 17 | + }, |
| 18 | + body: userCreate, |
| 19 | + }).then(response => { |
| 20 | + userId = response.body.id; |
| 21 | + expect(response.status).to.eq(200); |
| 22 | + expect(response.body).to.have.property('username', 'cypress1'); |
| 23 | + expect(response.body).to.have.property('role', 'user'); |
| 24 | + }); |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + it('Creates a team.', () => { |
| 29 | + cy.fixture('teams').then(data => { |
| 30 | + const teamCreate = data.teamCreate; |
| 31 | + cy.request({ |
| 32 | + method: 'POST', |
| 33 | + url: '/api/teams', |
| 34 | + headers: { |
| 35 | + 'Content-Type': 'application/json', |
| 36 | + Authorization: Cypress.env('authorization'), |
| 37 | + }, |
| 38 | + body: teamCreate, |
| 39 | + }).then(response => { |
| 40 | + teamId = response.body[0].id; |
| 41 | + expect(response.status).to.eq(200); |
| 42 | + expect(response.body[0]).to.have.property('name', 'cypress'); |
| 43 | + expect(response.body[1]).to.have.property('role', 'team-owner'); |
| 44 | + }); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + it('Gets a teams by ID.', () => { |
| 49 | + cy.request({ |
| 50 | + method: 'GET', |
| 51 | + url: `/api/teams/${teamId}`, |
| 52 | + headers: { |
| 53 | + 'Content-Type': 'application/json', |
| 54 | + Authorization: Cypress.env('authorization'), |
| 55 | + }, |
| 56 | + }).then(response => { |
| 57 | + expect(response.status).to.eq(200); |
| 58 | + expect(response.body).to.have.property('id', teamId); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + it('Updates a team.', () => { |
| 63 | + cy.fixture('teams').then(data => { |
| 64 | + const teamUpdate = data.teamUpdate; |
| 65 | + cy.request({ |
| 66 | + method: 'POST', |
| 67 | + url: `/api/teams/${teamId}`, |
| 68 | + headers: { |
| 69 | + 'Content-Type': 'application/json', |
| 70 | + Authorization: Cypress.env('authorization'), |
| 71 | + }, |
| 72 | + body: teamUpdate, |
| 73 | + }).then(response => { |
| 74 | + expect(response.status).to.eq(200); |
| 75 | + expect(response.body).to.have.property('id', teamId); |
| 76 | + expect(response.body).to.have.property('name', 'cypressUpdate'); |
| 77 | + }); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + it('Get all users that belong to a team.', () => { |
| 82 | + cy.request({ |
| 83 | + method: 'GET', |
| 84 | + url: `/api/teams/${teamId}/users`, |
| 85 | + headers: { |
| 86 | + 'Content-Type': 'application/json', |
| 87 | + Authorization: Cypress.env('authorization'), |
| 88 | + }, |
| 89 | + }).then(response => { |
| 90 | + expect(response.status).to.eq(200); |
| 91 | + expect(response.body.data[0]).to.have.property('id'); |
| 92 | + expect(response.body.data[0]).to.have.property('teamId'); |
| 93 | + expect(response.body.data[0]).to.have.property('userId'); |
| 94 | + expect(response.body.data[0]).to.have.property('user'); |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
| 98 | + it('Get a user belonging to a team.', () => { |
| 99 | + cy.request({ |
| 100 | + method: 'GET', |
| 101 | + url: `/api/teams/${teamId}/users/${Cypress.env('umami_user_id')}`, |
| 102 | + headers: { |
| 103 | + 'Content-Type': 'application/json', |
| 104 | + Authorization: Cypress.env('authorization'), |
| 105 | + }, |
| 106 | + }).then(response => { |
| 107 | + expect(response.status).to.eq(200); |
| 108 | + expect(response.body).to.have.property('teamId'); |
| 109 | + expect(response.body).to.have.property('userId'); |
| 110 | + expect(response.body).to.have.property('role'); |
| 111 | + }); |
| 112 | + }); |
| 113 | + |
| 114 | + it('Get all websites belonging to a team.', () => { |
| 115 | + cy.request({ |
| 116 | + method: 'GET', |
| 117 | + url: `/api/teams/${teamId}/websites`, |
| 118 | + headers: { |
| 119 | + 'Content-Type': 'application/json', |
| 120 | + Authorization: Cypress.env('authorization'), |
| 121 | + }, |
| 122 | + }).then(response => { |
| 123 | + expect(response.status).to.eq(200); |
| 124 | + expect(response.body).to.have.property('data'); |
| 125 | + }); |
| 126 | + }); |
| 127 | + |
| 128 | + it('Add a user to a team.', () => { |
| 129 | + cy.request({ |
| 130 | + method: 'POST', |
| 131 | + url: `/api/teams/${teamId}/users`, |
| 132 | + headers: { |
| 133 | + 'Content-Type': 'application/json', |
| 134 | + Authorization: Cypress.env('authorization'), |
| 135 | + }, |
| 136 | + body: { |
| 137 | + userId, |
| 138 | + role: 'team-member', |
| 139 | + }, |
| 140 | + }).then(response => { |
| 141 | + expect(response.status).to.eq(200); |
| 142 | + expect(response.body).to.have.property('userId', userId); |
| 143 | + expect(response.body).to.have.property('role', 'team-member'); |
| 144 | + }); |
| 145 | + }); |
| 146 | + |
| 147 | + it(`Update a user's role on a team.`, () => { |
| 148 | + cy.request({ |
| 149 | + method: 'POST', |
| 150 | + url: `/api/teams/${teamId}/users/${userId}`, |
| 151 | + headers: { |
| 152 | + 'Content-Type': 'application/json', |
| 153 | + Authorization: Cypress.env('authorization'), |
| 154 | + }, |
| 155 | + body: { |
| 156 | + role: 'team-view-only', |
| 157 | + }, |
| 158 | + }).then(response => { |
| 159 | + expect(response.status).to.eq(200); |
| 160 | + expect(response.body).to.have.property('userId', userId); |
| 161 | + expect(response.body).to.have.property('role', 'team-view-only'); |
| 162 | + }); |
| 163 | + }); |
| 164 | + |
| 165 | + it(`Remove a user from a team.`, () => { |
| 166 | + cy.request({ |
| 167 | + method: 'DELETE', |
| 168 | + url: `/api/teams/${teamId}/users/${userId}`, |
| 169 | + headers: { |
| 170 | + 'Content-Type': 'application/json', |
| 171 | + Authorization: Cypress.env('authorization'), |
| 172 | + }, |
| 173 | + }).then(response => { |
| 174 | + expect(response.status).to.eq(200); |
| 175 | + }); |
| 176 | + }); |
| 177 | + |
| 178 | + it('Deletes a team.', () => { |
| 179 | + cy.request({ |
| 180 | + method: 'DELETE', |
| 181 | + url: `/api/teams/${teamId}`, |
| 182 | + headers: { |
| 183 | + 'Content-Type': 'application/json', |
| 184 | + Authorization: Cypress.env('authorization'), |
| 185 | + }, |
| 186 | + }).then(response => { |
| 187 | + expect(response.status).to.eq(200); |
| 188 | + expect(response.body).to.have.property('ok', true); |
| 189 | + }); |
| 190 | + }); |
| 191 | + |
| 192 | + // it('Gets all teams that belong to a user.', () => { |
| 193 | + // cy.request({ |
| 194 | + // method: 'GET', |
| 195 | + // url: `/api/users/${userId}/teams`, |
| 196 | + // headers: { |
| 197 | + // 'Content-Type': 'application/json', |
| 198 | + // Authorization: Cypress.env('authorization'), |
| 199 | + // }, |
| 200 | + // }).then(response => { |
| 201 | + // expect(response.status).to.eq(200); |
| 202 | + // expect(response.body).to.have.property('data'); |
| 203 | + // }); |
| 204 | + // }); |
| 205 | + |
| 206 | + after(() => { |
| 207 | + cy.deleteUser(userId); |
| 208 | + }); |
| 209 | +}); |
0 commit comments