-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MLPAB-1855: Enable non-admins to edit details (#1071)
- Loading branch information
Showing
22 changed files
with
348 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,111 @@ | ||
describe('Edit member', () => { | ||
beforeEach(() => { | ||
cy.visit("/fixtures/supporter?organisation=1&redirect=/manage-organisation/manage-team-members&members=1"); | ||
describe('admin', () => { | ||
it('can edit a team members name', () => { | ||
cy.visit("/fixtures/supporter?organisation=1&redirect=/manage-organisation/manage-team-members&members=1&permission=admin"); | ||
|
||
cy.url().should('contain', "/manage-organisation/manage-team-members"); | ||
cy.contains('a', "Alice Moxom").click() | ||
cy.url().should('contain', "/manage-organisation/manage-team-members"); | ||
cy.contains('a', "Alice Moxom").click() | ||
|
||
cy.url().should('contain', "/manage-organisation/manage-team-members/edit-team-member"); | ||
}); | ||
cy.url().should('contain', "/manage-organisation/manage-team-members/edit-team-member"); | ||
|
||
it('can edit a team members name', () => { | ||
cy.checkA11yApp(); | ||
cy.checkA11yApp(); | ||
|
||
cy.get('#f-first-names').clear().type('John'); | ||
cy.get('#f-last-name').clear().type('Doe'); | ||
cy.get('#f-first-names').clear().type('John'); | ||
cy.get('#f-last-name').clear().type('Doe'); | ||
|
||
cy.contains('button', "Save").click() | ||
cy.contains('button', "Save").click() | ||
|
||
cy.url().should('contain', "/manage-organisation/manage-team-members"); | ||
cy.url().should('contain', "/manage-organisation/manage-team-members"); | ||
|
||
cy.contains('Team member’s name updated to John Doe'); | ||
cy.contains('a', "John Doe") | ||
}) | ||
cy.checkA11yApp(); | ||
|
||
cy.contains('Team member’s name updated to John Doe'); | ||
cy.contains('a', "John Doe") | ||
}) | ||
|
||
it('can edit own name', () => { | ||
cy.visit("/fixtures/supporter?organisation=1&redirect=/manage-organisation/manage-team-members&members=1&[email protected]&permission=admin"); | ||
|
||
cy.url().should('contain', "/manage-organisation/manage-team-members"); | ||
cy.contains('a', "Alice Moxom").click() | ||
|
||
cy.url().should('contain', "/manage-organisation/manage-team-members/edit-team-member"); | ||
|
||
it('can edit own name', () => { | ||
// TODO update to a full test when admins can set their own names during org creation | ||
cy.visit("/supporter/manage-organisation/manage-team-members?nameUpdated=John+Doe&selfUpdated=1"); | ||
cy.checkA11yApp(); | ||
|
||
cy.contains('Your name has been updated to John Doe'); | ||
cy.get('#f-first-names').clear().type('John'); | ||
cy.get('#f-last-name').clear().type('Doe'); | ||
|
||
cy.contains('button', "Save").click() | ||
|
||
cy.url().should('contain', "/manage-organisation/manage-team-members"); | ||
|
||
cy.checkA11yApp(); | ||
|
||
cy.contains('Your name has been updated to John Doe'); | ||
cy.contains('a', "John Doe") | ||
}) | ||
}) | ||
|
||
it('errors when empty', () => { | ||
cy.get('#f-first-names').clear(); | ||
cy.get('#f-last-name').clear(); | ||
describe('non-admin', () => { | ||
it('can edit own name', () => { | ||
cy.visit("/fixtures/supporter?organisation=1&redirect=/manage-organisation/manage-team-members&members=1&[email protected]"); | ||
|
||
cy.contains('a', 'Manage your details').click(); | ||
cy.url().should('contain', "/manage-organisation/manage-team-members/edit-team-member"); | ||
|
||
cy.checkA11yApp(); | ||
cy.contains('Your name'); | ||
|
||
cy.contains('button', "Save").click() | ||
cy.get('#f-first-names').clear ().type('John'); | ||
cy.get('#f-last-name').clear().type('Doe'); | ||
|
||
cy.checkA11yApp(); | ||
cy.contains('button', "Save").click() | ||
|
||
cy.get('.govuk-error-summary').within(() => { | ||
cy.contains('Enter first names'); | ||
cy.contains('Enter last name'); | ||
cy.url().should('contain', "/dashboard"); | ||
|
||
cy.checkA11yApp(); | ||
cy.contains('Your name has been updated to John Doe'); | ||
}) | ||
}) | ||
|
||
describe('errors', () => { | ||
beforeEach(() => { | ||
cy.visit("/fixtures/supporter?organisation=1&redirect=/manage-organisation/manage-team-members&members=1"); | ||
|
||
cy.url().should('contain', "/manage-organisation/manage-team-members"); | ||
cy.contains('a', "Alice Moxom").click() | ||
|
||
cy.url().should('contain', "/manage-organisation/manage-team-members/edit-team-member"); | ||
}); | ||
|
||
cy.contains('[for=f-first-names] + .govuk-error-message', 'Enter first names'); | ||
cy.contains('[for=f-last-name] + .govuk-error-message', 'Enter last name'); | ||
}); | ||
it('errors when empty', () => { | ||
cy.get('#f-first-names').clear(); | ||
cy.get('#f-last-name').clear(); | ||
|
||
it('errors when names too long', () => { | ||
cy.get('#f-first-names').invoke('val', 'a '.repeat(54)); | ||
cy.get('#f-last-name').invoke('val', 'b '.repeat(62)); | ||
cy.contains('button', "Save").click() | ||
|
||
cy.contains('button', "Save").click() | ||
cy.checkA11yApp(); | ||
|
||
cy.checkA11yApp(); | ||
cy.get('.govuk-error-summary').within(() => { | ||
cy.contains('Enter first names'); | ||
cy.contains('Enter last name'); | ||
}); | ||
|
||
cy.contains('[for=f-first-names] + .govuk-error-message', 'First names must be 53 characters or less'); | ||
cy.contains('[for=f-last-name] + .govuk-error-message', 'Last name must be 61 characters or less'); | ||
cy.contains('[for=f-first-names] + .govuk-error-message', 'Enter first names'); | ||
cy.contains('[for=f-last-name] + .govuk-error-message', 'Enter last name'); | ||
}); | ||
|
||
it('errors when names too long', () => { | ||
cy.get('#f-first-names').invoke('val', 'a '.repeat(54)); | ||
cy.get('#f-last-name').invoke('val', 'b '.repeat(62)); | ||
|
||
cy.contains('button', "Save").click() | ||
|
||
cy.checkA11yApp(); | ||
|
||
cy.contains('[for=f-first-names] + .govuk-error-message', 'First names must be 53 characters or less'); | ||
cy.contains('[for=f-last-name] + .govuk-error-message', 'Last name must be 61 characters or less'); | ||
}); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,11 +27,12 @@ func TestOrganisationStoreCreate(t *testing.T) { | |
|
||
dynamoClient.EXPECT(). | ||
Create(ctx, &actor.Member{ | ||
PK: "ORGANISATION#a-uuid", | ||
SK: "MEMBER#an-id", | ||
ID: "a-uuid", | ||
CreatedAt: testNow, | ||
Email: "[email protected]", | ||
PK: "ORGANISATION#a-uuid", | ||
SK: "MEMBER#an-id", | ||
ID: "a-uuid", | ||
CreatedAt: testNow, | ||
Email: "[email protected]", | ||
Permission: actor.Admin, | ||
}). | ||
Return(nil). | ||
Once() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,16 +33,18 @@ func Supporter(sessionStore sesh.Store, organisationStore OrganisationStore, don | |
members = r.FormValue("members") | ||
organisation = r.FormValue("organisation") | ||
redirect = r.FormValue("redirect") | ||
asMember = r.FormValue("asMember") | ||
permission = r.FormValue("permission") | ||
|
||
supporterSub = random.String(16) | ||
supporterSessionID = base64.StdEncoding.EncodeToString([]byte(supporterSub)) | ||
ctx = page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: supporterSessionID, Email: testEmail}) | ||
supporterCtx = page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: supporterSessionID, Email: testEmail}) | ||
) | ||
|
||
loginSession := &sesh.LoginSession{Sub: supporterSub, Email: testEmail} | ||
|
||
if organisation == "1" { | ||
org, err := organisationStore.Create(ctx, random.String(12)) | ||
org, err := organisationStore.Create(supporterCtx, random.String(12)) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -87,29 +89,50 @@ func Supporter(sessionStore sesh.Store, organisationStore OrganisationStore, don | |
|
||
if members != "" { | ||
n, err := strconv.Atoi(members) | ||
if err != nil { | ||
return fmt.Errorf("members should be a number") | ||
} | ||
|
||
memberEmailSub := make(map[string]string) | ||
|
||
permission, err := actor.ParsePermission(permission) | ||
if err != nil { | ||
permission = actor.None | ||
} | ||
|
||
for i, member := range orgMemberNames { | ||
if i == n { | ||
break | ||
} | ||
|
||
email := strings.ToLower(fmt.Sprintf("%s-%[email protected]", member.Firstnames, member.Lastname)) | ||
sub := []byte(random.String(16)) | ||
memberCtx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: base64.StdEncoding.EncodeToString(sub), Email: email}) | ||
|
||
if err = memberStore.Create( | ||
page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: random.String(12)}), | ||
memberCtx, | ||
&actor.MemberInvite{ | ||
PK: random.String(12), | ||
SK: random.String(12), | ||
CreatedAt: time.Now(), | ||
UpdatedAt: time.Now(), | ||
OrganisationID: org.ID, | ||
Email: strings.ToLower(fmt.Sprintf("%s-%[email protected]", member.Firstnames, member.Lastname)), | ||
Email: email, | ||
FirstNames: member.Firstnames, | ||
LastName: member.Lastname, | ||
Permission: actor.Admin, | ||
Permission: permission, | ||
ReferenceNumber: random.String(12), | ||
}, | ||
); err != nil { | ||
return err | ||
} | ||
|
||
memberEmailSub[email] = string(sub) | ||
} | ||
|
||
if sub, found := memberEmailSub[asMember]; found { | ||
loginSession.Email = asMember | ||
loginSession.Sub = sub | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.