Skip to content

Commit

Permalink
basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
TuvalSimha committed Oct 19, 2024
1 parent 51f5a77 commit 1cb929e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
41 changes: 41 additions & 0 deletions integration-tests/tests/api/audit-log/creation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { graphql } from 'testkit/gql';
import { execute } from '../../../testkit/graphql';
import { initSeed } from '../../../testkit/seed';

describe('Audit Logs Creation', () => {
describe('Organization', () => {
const query = graphql(`
query MyQuery($selector: OrganizationSelectorInput!) {
auditLogs(selector: $selector) {
nodes {
eventTime
id
__typename
}
}
}
`);
test.concurrent(
'Should be only one audit log for organization creation',
async ({ expect }) => {
const { ownerToken, createOrg } = await initSeed().createOwner();
const { organization } = await createOrg();

const result = await execute({
document: query,
variables: {
selector: {
organization: organization.id,
},
},
authToken: ownerToken,
});
expect(result.rawBody.data?.auditLogs.nodes).not.toBeNull();
expect(result.rawBody.data?.auditLogs.nodes.length).toBeGreaterThan(0);
expect(result.rawBody.data?.auditLogs.nodes[0].__typename).toBe(
'OrganizationCreatedAuditLog',
);
},
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,21 @@ export class AuditLogManager {
throw new Error('Organization ID is required');
}
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
const sqlLimit = sql.raw(props.pagination?.limit?.toString()!);
const sqlLimit = sql.raw(props.pagination?.limit?.toString() ?? '25');
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
const sqlOffset = sql.raw(props.pagination?.offset?.toString()!);
const sqlOffset = sql.raw(props.pagination?.offset?.toString() ?? '0');

let where: SqlValue[] = [];
where.push(sql`organization_id = ${props.selector.organization}`);

if (props.filter) {
if (props.filter?.userId) {
where.push(sql`user_id = ${props.filter.userId}`);
}
if (props.filter?.startDate && props.filter?.endDate) {
const from = formatToClickhouseDateTime(props.filter.startDate.toISOString());
const to = formatToClickhouseDateTime(props.filter.endDate.toISOString());
where.push(sql`event_time >= ${from} AND event_time <= ${to}`);
}
if (props.filter?.userId) {
where.push(sql`user_id = ${props.filter.userId}`);
}

if (props.filter?.startDate && props.filter?.endDate) {
const from = formatToClickhouseDateTime(props.filter.startDate.toISOString());
const to = formatToClickhouseDateTime(props.filter.endDate.toISOString());
where.push(sql`event_time >= ${from} AND event_time <= ${to}`);
}

const whereClause = where.length > 0 ? sql`WHERE ${sql.join(where, ' AND ')}` : sql``;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export const createOrganization: NonNullable<MutationResolvers['createOrganizati
{
eventType: 'ORGANIZATION_CREATED',
organizationCreatedAuditLogSchema: {
organizationId: result.id,
organizationName: result.name,
organizationId: result.organization.id,
organizationName: result.organization.name,
},
},
{
organizationId: result.id,
organizationId: result.organization.id,
userEmail: user.email,
userId: user.id,
user: user,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { z } from 'zod';
import { Target } from '../../../../shared/entities';
import { assertOk } from '../../../../shared/helpers';
import { AuditLogManager } from '../../../audit-logs/providers/audit-logs-manager';
import { AuthManager } from '../../../auth/providers/auth-manager';
import { OrganizationManager } from '../../../organization/providers/organization-manager';
import { IdTranslator } from '../../../shared/providers/id-translator';
import { Logger } from '../../../shared/providers/logger';
import { TargetManager } from '../../../target/providers/target-manager';
import { ProjectManager } from '../../providers/project-manager';
import { ProjectSlugModel } from '../../validation';
import type { MutationResolvers } from './../../../../__generated__/types.next';
import { AuthManager } from '../../../auth/providers/auth-manager';
import { AuditLogManager } from '../../../audit-logs/providers/audit-logs-manager';

export const createProject: NonNullable<MutationResolvers['createProject']> = async (
_,
Expand Down

0 comments on commit 1cb929e

Please sign in to comment.