-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add methods for the team model #1520
Conversation
adba519
to
a8a491f
Compare
TODO: Add getAll and assignToFleet methods |
organizationSlugOrId: string | number, | ||
options: BalenaSdk.PineOptions<BalenaSdk.Team> = {}, | ||
): Promise<BalenaSdk.Team[]> { | ||
return pine.get({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Mark it as async
- then add a throw in case organizationSlugOrId is unexpected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean by adding a pine.get(resource: 'organization', ...) or by checking if the argument is of type string | number ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with either :) IE
- Checking for number/string and throwing invalid parameter error
- doing just a
sdk.modelsorganization.get()
5d538d1
to
070952a
Compare
) { | ||
const { pine, sdkInstance } = deps; | ||
|
||
const getRoleId = async (roleName: BalenaSdk.ApplicationMembershipRoles) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method is repeated in multiple files with different implementations, is that fine if I move it to /utils/index.ts to reuse it @thgreasi ?
teamId: number, | ||
options: BalenaSdk.PineOptions<BalenaSdk.TeamApplicationAccess> = {}, | ||
): Promise<BalenaSdk.TeamApplicationAccess[]> { | ||
return sdkInstance.pine.get({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we check that the teamId exist ?
teamId: number, | ||
applicationIdOrSlug: number | string, | ||
roleName: BalenaSdk.ApplicationMembershipRoles, | ||
): Promise<BalenaSdk.TeamApplicationAccess> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that the API already throws an error when the teamId doesn't exist, but it returns a generic internal server error. I was trying to avoid the additional request 🤔 but what do you think? Should we throw a more specific error ?
* }); | ||
*/ | ||
const update = async function ( | ||
teamApplicationAccessId: string | number, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the internal server error: the same issue applies here for teamApplicationAccessId
applicationIdOrSlug: number | string, | ||
roleName: BalenaSdk.ApplicationMembershipRoles, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure, but do you think it's worth updating this method to accept one of the following options?
For example:
applicationIdOrSlug: number | string | number[] | string[]
roleName: BalenaSdk.ApplicationMembershipRoles | BalenaSdk.ApplicationMembershipRoles[]
Or alternatively:
applicationSlugOrIdAndRole: { idOrSlug: number | string, roleName: BalenaSdk.ApplicationMembershipRoles }[]
(just consider the idea not names that I gave as an example)
And then wrapping it in a batch function from utils. What do you think?
070952a
to
5beff33
Compare
40c47ed
to
cbebf6f
Compare
it('should be rejected if the team does not exists', function () { | ||
const promise = balena.models.team.rename( | ||
999999, | ||
`new_rename_${TEST_TEAM_NAME}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`new_rename_${TEST_TEAM_NAME}`, | |
`${TEST_TEAM_NAME}_new_rename`, |
it('should be able to create a new team, using organization id', async function () { | ||
const teamName = `${TEST_TEAM_NAME}_${Date.now()}`; | ||
const team = await balena.models.team.create( | ||
ctx.initialOrganization.id, | ||
teamName, | ||
); | ||
ctx.newTeam1 = team; | ||
expect(team).to.have.property('name', teamName); | ||
}); | ||
it('should be able to create a new team, using organization handle', async function () { | ||
const teamName = `${TEST_TEAM_NAME}_${Date.now()}_2`; | ||
const team = await balena.models.team.create( | ||
ctx.initialOrganization.handle, | ||
teamName, | ||
); | ||
ctx.newTeam2 = team; | ||
expect(team).to.have.property('name', teamName); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('should be able to create a new team, using organization id', async function () { | |
const teamName = `${TEST_TEAM_NAME}_${Date.now()}`; | |
const team = await balena.models.team.create( | |
ctx.initialOrganization.id, | |
teamName, | |
); | |
ctx.newTeam1 = team; | |
expect(team).to.have.property('name', teamName); | |
}); | |
it('should be able to create a new team, using organization handle', async function () { | |
const teamName = `${TEST_TEAM_NAME}_${Date.now()}_2`; | |
const team = await balena.models.team.create( | |
ctx.initialOrganization.handle, | |
teamName, | |
); | |
ctx.newTeam2 = team; | |
expect(team).to.have.property('name', teamName); | |
}); | |
for (const propName of organizationRetrievalFields) { | |
it(`should be able to create a new team, using organization ${propName}`, async function () { | |
const teamName = `${TEST_TEAM_NAME}_${Date.now()}_${propName}`; | |
const team = await balena.models.team.create( | |
ctx.initialOrganization[propName], | |
teamName, | |
); | |
ctx.newTeam1 = team; | |
expect(team).to.have.property('name', teamName); | |
}); | |
} |
cbebf6f
to
bf0afe5
Compare
Change-type: minor
Change-type: minor
bf0afe5
to
8e1e3cb
Compare
Change-type: minor
Resolves: #
HQ:
See:
Depends-on:
Change-type: major|minor|patch
Contributor checklist