Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
pontussjostedt committed Nov 10, 2023
1 parent f3d1354 commit da769be
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 35 deletions.
30 changes: 0 additions & 30 deletions src/api/access.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,6 @@ export class AccessAPI {
return access;
}

/**
*
* @param door target door which you want to get all users with access to
*/
async getIndividualAccessForDoor(door: Door): Promise<PrismaUser[]> {
const usersWithAccess = await prisma.prismaUser.findMany({
where: {
access: {
some: {
resource: door,
},
},
},
include: {
access: true,
},
});
return usersWithAccess;
}

async getAllIndividualAccess(): Promise<PrismaIndividualAccess[]> {
const access = await prisma.prismaIndividualAccess.findMany({
orderBy: {
resource: 'asc',
},
});

return access;
}

/**
* Get access for a post in alphabetical order
* @param postId ID for the post
Expand Down
3 changes: 0 additions & 3 deletions src/resolvers/access.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Context } from '@/models/context';
import { hasAccess, hasAuthenticated } from '@/util';
import { AccessAPI } from '@api/access';
import { Door, Feature, Resolvers } from '@generated/graphql';
import { PrismaUser } from '@prisma/client';
import { accessReducer, doorReducer, featureReducer } from '@reducer/access';
import { userReduce } from '@reducer/user';

const accessApi = new AccessAPI();

Expand Down
1 change: 0 additions & 1 deletion src/schemas/access.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
type Query {
individualAccess(username: String!): Access!
postAccess(postId: Int!): Access!
individualAccessForDoor(door: Door!): [User!]!
features: [FeatureInfo!]!
doors: [DoorInfo!]!
}
Expand Down
15 changes: 14 additions & 1 deletion test/integration/access.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('setting/getting access for user', () => {
() =>
accessApi.setIndividualAccess(username, input);
const getAccess = (username = username0) => accessApi.getIndividualAccess(username);

const getAllIndividualAccessUsers = () => userApi.getUsersWithIndividualAccess();
it('setting single access', async () => {
const expectedAccess = mapUserAccess(expectedAccessSingleInput);

Expand All @@ -197,6 +197,19 @@ describe('setting/getting access for user', () => {
await setGetTest(setAccess(accessMultipleInput), getAccess, expectedAccess);
});

//This seems kinda iffy
it('getting all access users', async () => {
const accessUsers = await getAllIndividualAccessUsers();

const usernamesToCheck = ['aa0000bb-s', username0]; // Add usernames to check

expect(accessUsers).toEqual(
expect.arrayContaining(
usernamesToCheck.map((username) => expect.objectContaining({ username }))

Check failure on line 208 in test/integration/access.api.test.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

test/integration/access.api.test.ts#L208

[@typescript-eslint/no-unsafe-return] Unsafe return of an `any` typed value.
)
);
});

it('removing access', async () => {
await setGetTest(setAccess(emptyAccess), getAccess, []);
});
Expand Down

0 comments on commit da769be

Please sign in to comment.