Skip to content

Commit

Permalink
fix test case and lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hdiniz committed Dec 11, 2024
1 parent 2af5785 commit 02ccd18
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
13 changes: 2 additions & 11 deletions server/graphql/common/expenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2003,12 +2003,7 @@ export async function submitExpenseDraft(

await checkLockedFields(existingExpense, { ...expenseData, payee: requestedPayee || args.expense.payee });

const options = {
overrideRemoteUser: undefined,
skipPermissionCheck: true,
skipActivity: true,
draftKey: args.draftKey,
};
const options = { overrideRemoteUser: undefined, skipPermissionCheck: true, skipActivity: true };
if (requestedPayee) {
if (!req.remoteUser?.isAdminOfCollective(requestedPayee)) {
throw new Unauthorized('User needs to be the admin of the payee to submit an expense on their behalf');
Expand Down Expand Up @@ -2156,11 +2151,7 @@ export async function sendDraftExpenseInvite(
}
}

export async function editExpenseDraft(
req: express.Request,
expenseData: ExpenseData,
args: Record<string, any> & { draftKey?: string },
) {
export async function editExpenseDraft(req: express.Request, expenseData: ExpenseData, args: Record<string, any>) {
const existingExpense = await models.Expense.findByPk(expenseData.id, {
include: [{ model: models.ExpenseItem, as: 'items' }],
});
Expand Down
12 changes: 8 additions & 4 deletions server/graphql/v2/object/Expense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,15 @@ export const GraphQLExpense = new GraphQLObjectType<ExpenseModel, express.Reques
item.url = uploadedFile
? UploadedFile.getProtectedURLFromOpenCollectiveS3Bucket(uploadedFile, {
expenseId: expense.id,
draftKey: req?.remoteUser ? null : expense.data.draftKey,
draftKey: req.remoteUser ? null : expense.data.draftKey,
})
: item.url;
}
}

draftData.items = items;
if (items.length > 0) {
draftData.items = items;
}

const attachedFiles = (draftData.attachedFiles as { url?: string }[]) || [];
for (const attachedFile of attachedFiles) {
Expand All @@ -576,13 +578,15 @@ export const GraphQLExpense = new GraphQLObjectType<ExpenseModel, express.Reques
attachedFile.url = uploadedFile
? UploadedFile.getProtectedURLFromOpenCollectiveS3Bucket(uploadedFile, {
expenseId: expense.id,
draftKey: req?.remoteUser ? null : expense.data.draftKey,
draftKey: req.remoteUser ? null : expense.data.draftKey,
})
: attachedFile.url;
}
}

draftData.attachedFiles = attachedFiles;
if (attachedFiles.length > 0) {
draftData.attachedFiles = attachedFiles;
}

return draftData;
}
Expand Down
4 changes: 2 additions & 2 deletions test/server/controllers/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ describe('server/controllers/files', () => {
});

describe('authenticated access to files', () => {
it('should return 401 if not logged in', async () => {
it('should return 403 if not logged in', async () => {
const response = await makeRequest(uploadedFile.id);

expect(response._getStatusCode()).to.eql(401);
expect(response._getStatusCode()).to.eql(403);
});

it('should return 400 if malformed request', async () => {
Expand Down
7 changes: 4 additions & 3 deletions test/server/graphql/v2/mutation/ExpenseMutations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4968,10 +4968,11 @@ describe('server/graphql/v2/mutation/ExpenseMutations', () => {

result.errors && console.error(result.errors);
expect(result.errors).to.not.exist;
const email = await waitForCondition(() => {
return emailLib.sendMessage.getCalls().find(call => call.firstArg === existingUser.email);
});

await waitForCondition(() => emailLib.sendMessage.thirdCall);

const [recipient] = emailLib.sendMessage.thirdCall.args;
const [recipient] = email.args;
expect(recipient).to.eq(existingUser.email);
});

Expand Down
2 changes: 1 addition & 1 deletion test/test-helpers/fake-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export const fakeUploadedFile = async (fileData: Partial<InferCreationAttributes
fileName,
fileType,
...fileData,
CreatedByUserId: <number>fileData.CreatedByUserId || (await fakeUser()).id,
CreatedByUserId: <number>fileData?.CreatedByUserId || (await fakeUser()).id,
});
};

Expand Down

0 comments on commit 02ccd18

Please sign in to comment.