-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add update organization usecase, command - Create a PUT endpoint to /organizations - Add e2e test for updating the organization name
- Loading branch information
Blessing Makaraba
authored and
Blessing Makaraba
committed
Jan 28, 2023
1 parent
1ede901
commit 22f4c49
Showing
6 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
apps/api/src/app/organization/e2e/update-organization.e2e.ts
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { OrganizationRepository } from '@novu/dal'; | ||
import { UserSession } from '@novu/testing'; | ||
import { expect } from 'chai'; | ||
|
||
describe('Update Organization - /organizations (PUT)', function () { | ||
let session: UserSession; | ||
const organizationRepository = new OrganizationRepository(); | ||
|
||
beforeEach(async () => { | ||
session = new UserSession(); | ||
await session.initialize(); | ||
}); | ||
|
||
it('should update the organization name', async function () { | ||
const payload = { | ||
name: 'Liberty Powers', | ||
}; | ||
|
||
await session.testAgent.put('/v1/organizations').send(payload); | ||
|
||
const organization = await organizationRepository.findById(session.organization._id); | ||
|
||
expect(organization.name).to.equal(payload.name); | ||
}); | ||
}); |
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
9 changes: 9 additions & 0 deletions
9
apps/api/src/app/organization/usecases/update-organization/update-organization-command.ts
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { IsDefined } from 'class-validator'; | ||
import { AuthenticatedCommand } from '../../../shared/commands/authenticated.command'; | ||
|
||
export class UpdateOrganizationCommand extends AuthenticatedCommand { | ||
@IsDefined() | ||
public readonly id: string; | ||
|
||
name: string; | ||
} |
18 changes: 18 additions & 0 deletions
18
apps/api/src/app/organization/usecases/update-organization/update-organization.usecase.ts
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { OrganizationRepository } from '@novu/dal'; | ||
import { UpdateOrganizationCommand } from './update-organization-command'; | ||
|
||
@Injectable() | ||
export class UpdateOrganization { | ||
constructor(private organizationRepository: OrganizationRepository) {} | ||
|
||
async execute(command: UpdateOrganizationCommand) { | ||
const payload = { | ||
name: command.name, | ||
}; | ||
|
||
await this.organizationRepository.updateOrganization(command.id, payload); | ||
|
||
return payload; | ||
} | ||
} |
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