Skip to content

Commit

Permalink
Support signing up with organization membership (#905)
Browse files Browse the repository at this point in the history
* Adding 'is_signup_enabled' support

* Adding required test-cases.
  • Loading branch information
nandan-bhat authored Jun 21, 2024
1 parent 16dee06 commit 9dc3067
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/tools/auth0/handlers/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const schema = {
connection_id: { type: 'string' },
assign_membership_on_login: { type: 'boolean' },
show_as_button: { type: 'boolean' },
is_signup_enabled: { type: 'boolean' }
},
},
},
Expand Down Expand Up @@ -127,8 +128,11 @@ export default class OrganizationsHandler extends DefaultHandler {
existingConnections.find(
(x) =>
x.connection_id === c.connection_id &&
(x.assign_membership_on_login !== c.assign_membership_on_login ||
x.show_as_button !== c.show_as_button)
(
x.assign_membership_on_login !== c.assign_membership_on_login ||
x.show_as_button !== c.show_as_button ||
x.is_signup_enabled !== c.is_signup_enabled
)
)
);

Expand All @@ -141,6 +145,7 @@ export default class OrganizationsHandler extends DefaultHandler {
{
assign_membership_on_login: conn.assign_membership_on_login,
show_as_button: conn.show_as_button,
is_signup_enabled: conn.is_signup_enabled
}
)
.catch(() => {
Expand Down
41 changes: 41 additions & 0 deletions test/context/directory/organizations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ describe('#directory context organizations', () => {
'{ "name": "acme", "display_name": "acme", "branding": { "colors": { "primary": "#3678e2", "page_background": "#9c4949" } }, "connections":[{ "name": "google", "assign_membership_on_login": false, "show_as_button": false }]}',
'contoso.json':
'{ "name": "contoso", "display_name": "contoso", "branding": { "colors": { "primary": "#3678e2", "page_background": "#9c4949" } }, "connections":[{ "name": "google", "assign_membership_on_login": false, "show_as_button": false }]}',
'tast-org.json':
'{ "name": "atko", "display_name": "Atko", "branding": { "colors": { "primary": "#ededed", "page_background": "#191919" } }, "connections":[{ "name": "Username-Password-Authentication", "assign_membership_on_login": true, "show_as_button": true, "is_signup_enabled": true }]}',
},
};

Expand Down Expand Up @@ -60,6 +62,24 @@ describe('#directory context organizations', () => {
},
],
},
{
name: 'atko',
display_name: 'Atko',
branding: {
colors: {
primary: '#ededed',
page_background: '#191919',
},
},
connections: [
{
name: 'Username-Password-Authentication',
assign_membership_on_login: true,
show_as_button: true,
is_signup_enabled: true,
}
],
},
];

expect(context.assets.organizations).to.deep.equal(target);
Expand Down Expand Up @@ -135,6 +155,24 @@ describe('#directory context organizations', () => {
},
],
},
{
name: 'atko',
display_name: 'Atko',
branding: {
colors: {
primary: '#ededed',
page_background: '#191919',
},
},
connections: [
{
name: 'Username-Password-Authentication',
assign_membership_on_login: true,
show_as_button: true,
is_signup_enabled: true,
},
],
},
];

await handler.dump(context);
Expand All @@ -145,5 +183,8 @@ describe('#directory context organizations', () => {
expect(loadJSON(path.join(organizationsFolder, 'contoso.json'))).to.deep.equal(
context.assets.organizations[1]
);
expect(loadJSON(path.join(organizationsFolder, 'atko.json'))).to.deep.equal(
context.assets.organizations[2]
);
});
});
5 changes: 5 additions & 0 deletions test/context/yaml/organizations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('#YAML context organizations', () => {
- connection_id: con_123
assign_membership_on_login: false
show_as_button: false
is_signup_enabled: false
display_name: acme
- name: contoso
branding:
Expand All @@ -33,6 +34,7 @@ describe('#YAML context organizations', () => {
- connection_id: con_456
assign_membership_on_login: true
show_as_button: true
is_signup_enabled: true
display_name: contoso
`;

Expand All @@ -51,6 +53,7 @@ describe('#YAML context organizations', () => {
connection_id: 'con_123',
assign_membership_on_login: false,
show_as_button: false,
is_signup_enabled: false
},
],
},
Expand All @@ -68,6 +71,7 @@ describe('#YAML context organizations', () => {
connection_id: 'con_456',
assign_membership_on_login: true,
show_as_button: true,
is_signup_enabled: true
},
],
},
Expand Down Expand Up @@ -99,6 +103,7 @@ describe('#YAML context organizations', () => {
connection_id: 'con_123',
assign_membership_on_login: false,
show_as_button: false,
is_signup_enabled: false,
connection: {
name: 'foo',
strategy: 'auth0',
Expand Down
7 changes: 7 additions & 0 deletions test/tools/auth0/handlers/organizations.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const sampleEnabledConnection = {
connection_id: 'con_123',
assign_membership_on_login: true,
show_as_button: false,
is_signup_enabled: true,
connection: {
name: 'Username-Password-Login',
strategy: 'auth0',
Expand Down Expand Up @@ -135,6 +136,7 @@ describe('#organizations handler', () => {
expect(connection.connection_id).to.equal('con_123');
expect(connection.assign_membership_on_login).to.equal(true);
expect(connection.show_as_button).to.equal(false);
expect(connection.is_signup_enabled).to.equal(true);
return Promise.resolve(connection);
},
},
Expand Down Expand Up @@ -169,6 +171,7 @@ describe('#organizations handler', () => {
name: 'Username-Password-Login',
assign_membership_on_login: true,
show_as_button: false,
is_signup_enabled: true
},
],
},
Expand Down Expand Up @@ -333,6 +336,7 @@ describe('#organizations handler', () => {
expect(data).to.be.an('object');
expect(data.assign_membership_on_login).to.equal(false);
expect(data.show_as_button).to.equal(true);
expect(data.is_signup_enabled).to.equal(false);
} else {
expect(params).to.be.an('object');
expect(params.id).to.equal('123');
Expand Down Expand Up @@ -377,6 +381,7 @@ describe('#organizations handler', () => {
name: 'Username-Password-Login',
assign_membership_on_login: false,
show_as_button: true,
is_signup_enabled: false
},
{ name: 'facebook', assign_membership_on_login: true, show_as_button: false },
],
Expand Down Expand Up @@ -409,6 +414,7 @@ describe('#organizations handler', () => {
expect(data.connection_id).to.equal('con_123');
expect(data.assign_membership_on_login).to.equal(false);
expect(data.show_as_button).to.equal(false);
expect(data.is_signup_enabled).to.equal(false);
return Promise.resolve(data);
},
},
Expand Down Expand Up @@ -445,6 +451,7 @@ describe('#organizations handler', () => {
name: 'Username-Password-Login',
assign_membership_on_login: false,
show_as_button: false,
is_signup_enabled: false
},
],
},
Expand Down

0 comments on commit 9dc3067

Please sign in to comment.