Skip to content

Commit

Permalink
fix: analysis-permission test-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Jul 1, 2024
1 parent 30cba38 commit 52dfa43
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,28 @@ export async function runAnalysisPermissionValidation(
throw e;
}

// todo: this is not possible right now :/
/*
const data = buildAbilityFromPermission(permission);
const ability = useRequestEnv(req, 'abilities');
if (!ability.has(data)) {
throw new ForbiddenError(`You don't own the permission ${data.name}`);
}
*/

try {
const policy = await authup.policy.getOne(result.data.policy_id);
if (result.data.policy_id) {
try {
const policy = await authup.policy.getOne(result.data.policy_id);

result.data.policy = policy;
result.data.policy_id = policy.id;
} catch (e) {
if (isClientErrorWithStatusCode(e, 404)) {
throw new BadRequestError(buildHTTPValidationErrorMessage('permission_id'));
}
result.data.policy = policy;
result.data.policy_id = policy.id;
} catch (e) {
if (isClientErrorWithStatusCode(e, 404)) {
throw new BadRequestError(buildHTTPValidationErrorMessage('permission_id'));
}

throw e;
throw e;
}
}
}

Expand Down
79 changes: 79 additions & 0 deletions packages/server-core/test/unit/http/analysis-permission.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2021-2024.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/

import { extendObject } from '@authup/kit';
import type { AnalysisPermission } from '@privateaim/core-kit';
import { isAuthupClientUsable, useAuthupClient } from '@privateaim/server-kit';
import {
createTestSuite,
expectPropertiesEqualToSrc,
removeDateProperties,
} from '../../utils';
import {
createTestNode, createTestProject,

Check failure on line 17 in packages/server-core/test/unit/http/analysis-permission.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'createTestNode' is defined but never used
} from '../../utils/domains';

describe('src/controllers/core/analysis-permission', () => {
const suite = createTestSuite();

beforeAll(async () => {
await suite.up();
});

afterAll(async () => {
await suite.down();
});

const attributes : Partial<AnalysisPermission> = {
permission_id: '667672f6-1c6b-468f-947f-6370cf18454c',
};

it('should create resource', async () => {
const client = suite.client();

const project = await client.project.create(createTestProject());
expect(project.id).toBeDefined();

const analysis = await client.analysis.create({
name: 'foo.bar.baz',
project_id: project.id,
});
expect(analysis.id).toBeDefined();

attributes.analysis_id = analysis.id;

// todo: maybe create authup policy
if (isAuthupClientUsable()) {
const authup = useAuthupClient();

const permission = await authup.permission.create({ name: 'analysis_permission' });
attributes.permission_id = permission.id;
}

const analysisPermission = await client.analysisPermission.create(attributes);
extendObject(attributes, removeDateProperties(analysisPermission));
});

it('should read collection', async () => {
const client = suite.client();
const { data } = await client.analysisPermission.getMany();
expect(data.length).toBeGreaterThanOrEqual(1);
});

it('should read resource', async () => {
const client = suite.client();

const data = await client.analysisPermission.getOne(attributes.id);
expectPropertiesEqualToSrc(attributes, data);
});

it('should delete resource', async () => {
const client = suite.client();

await client.analysisPermission.delete(attributes.id);
});
});
95 changes: 0 additions & 95 deletions packages/server-core/test/unit/http/analysis-permission.ts

This file was deleted.

0 comments on commit 52dfa43

Please sign in to comment.