test(create-step): make current and another user explicit
This commit is contained in:
@@ -16,6 +16,16 @@ describe('POST /api/v1/flows/:flowId/steps', () => {
|
|||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
currentUser = await createUser();
|
currentUser = await createUser();
|
||||||
|
|
||||||
|
flow = await createFlow({ userId: currentUser.id });
|
||||||
|
|
||||||
|
triggerStep = await createStep({ flowId: flow.id, type: 'trigger' });
|
||||||
|
|
||||||
|
await createStep({ flowId: flow.id, type: 'action' });
|
||||||
|
|
||||||
|
token = await createAuthTokenByUserId(currentUser.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return created step for current user', async () => {
|
||||||
await createPermission({
|
await createPermission({
|
||||||
roleId: currentUser.roleId,
|
roleId: currentUser.roleId,
|
||||||
subject: 'Flow',
|
subject: 'Flow',
|
||||||
@@ -30,15 +40,6 @@ describe('POST /api/v1/flows/:flowId/steps', () => {
|
|||||||
conditions: ['isCreator'],
|
conditions: ['isCreator'],
|
||||||
});
|
});
|
||||||
|
|
||||||
flow = await createFlow({ userId: currentUser.id });
|
|
||||||
|
|
||||||
triggerStep = await createStep({ flowId: flow.id, type: 'trigger' });
|
|
||||||
await createStep({ flowId: flow.id, type: 'action' });
|
|
||||||
|
|
||||||
token = await createAuthTokenByUserId(currentUser.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return created step for current user', async () => {
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post(`/api/v1/flows/${flow.id}/steps`)
|
.post(`/api/v1/flows/${flow.id}/steps`)
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
@@ -57,27 +58,35 @@ describe('POST /api/v1/flows/:flowId/steps', () => {
|
|||||||
|
|
||||||
it('should return created step for another user', async () => {
|
it('should return created step for another user', async () => {
|
||||||
const anotherUser = await createUser();
|
const anotherUser = await createUser();
|
||||||
const anotherUsertoken = await createAuthTokenByUserId(anotherUser.id);
|
|
||||||
|
const anotherUserFlow = await createFlow({ userId: anotherUser.id });
|
||||||
|
|
||||||
|
const anotherUserFlowTriggerStep = await createStep({
|
||||||
|
flowId: anotherUserFlow.id,
|
||||||
|
type: 'trigger',
|
||||||
|
});
|
||||||
|
|
||||||
|
await createStep({ flowId: anotherUserFlow.id, type: 'action' });
|
||||||
|
|
||||||
await createPermission({
|
await createPermission({
|
||||||
roleId: anotherUser.roleId,
|
roleId: currentUser.roleId,
|
||||||
subject: 'Flow',
|
subject: 'Flow',
|
||||||
action: 'read',
|
action: 'read',
|
||||||
conditions: [],
|
conditions: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
await createPermission({
|
await createPermission({
|
||||||
roleId: anotherUser.roleId,
|
roleId: currentUser.roleId,
|
||||||
subject: 'Flow',
|
subject: 'Flow',
|
||||||
action: 'update',
|
action: 'update',
|
||||||
conditions: [],
|
conditions: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post(`/api/v1/flows/${flow.id}/steps`)
|
.post(`/api/v1/flows/${anotherUserFlow.id}/steps`)
|
||||||
.set('Authorization', anotherUsertoken)
|
.set('Authorization', token)
|
||||||
.send({
|
.send({
|
||||||
previousStepId: triggerStep.id,
|
previousStepId: anotherUserFlowTriggerStep.id,
|
||||||
})
|
})
|
||||||
.expect(201);
|
.expect(201);
|
||||||
|
|
||||||
@@ -90,6 +99,20 @@ describe('POST /api/v1/flows/:flowId/steps', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return bad request response for invalid flow UUID', async () => {
|
it('should return bad request response for invalid flow UUID', async () => {
|
||||||
|
await createPermission({
|
||||||
|
roleId: currentUser.roleId,
|
||||||
|
subject: 'Flow',
|
||||||
|
action: 'read',
|
||||||
|
conditions: ['isCreator'],
|
||||||
|
});
|
||||||
|
|
||||||
|
await createPermission({
|
||||||
|
roleId: currentUser.roleId,
|
||||||
|
subject: 'Flow',
|
||||||
|
action: 'update',
|
||||||
|
conditions: ['isCreator'],
|
||||||
|
});
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
.post('/api/v1/flows/invalidFlowUUID/steps')
|
.post('/api/v1/flows/invalidFlowUUID/steps')
|
||||||
.set('Authorization', token)
|
.set('Authorization', token)
|
||||||
@@ -100,6 +123,20 @@ describe('POST /api/v1/flows/:flowId/steps', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return not found response for invalid flow UUID', async () => {
|
it('should return not found response for invalid flow UUID', async () => {
|
||||||
|
await createPermission({
|
||||||
|
roleId: currentUser.roleId,
|
||||||
|
subject: 'Flow',
|
||||||
|
action: 'read',
|
||||||
|
conditions: ['isCreator'],
|
||||||
|
});
|
||||||
|
|
||||||
|
await createPermission({
|
||||||
|
roleId: currentUser.roleId,
|
||||||
|
subject: 'Flow',
|
||||||
|
action: 'update',
|
||||||
|
conditions: ['isCreator'],
|
||||||
|
});
|
||||||
|
|
||||||
const notExistingFlowUUID = Crypto.randomUUID();
|
const notExistingFlowUUID = Crypto.randomUUID();
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
@@ -112,6 +149,20 @@ describe('POST /api/v1/flows/:flowId/steps', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return not found response for invalid flow UUID', async () => {
|
it('should return not found response for invalid flow UUID', async () => {
|
||||||
|
await createPermission({
|
||||||
|
roleId: currentUser.roleId,
|
||||||
|
subject: 'Flow',
|
||||||
|
action: 'read',
|
||||||
|
conditions: ['isCreator'],
|
||||||
|
});
|
||||||
|
|
||||||
|
await createPermission({
|
||||||
|
roleId: currentUser.roleId,
|
||||||
|
subject: 'Flow',
|
||||||
|
action: 'update',
|
||||||
|
conditions: ['isCreator'],
|
||||||
|
});
|
||||||
|
|
||||||
const notExistingStepUUID = Crypto.randomUUID();
|
const notExistingStepUUID = Crypto.randomUUID();
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
|
Reference in New Issue
Block a user