Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes made by updated codemod:call-async #18

Draft
wants to merge 1 commit into
base: 2.x.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions api/tasks/tasks.methods.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,48 @@ if (Meteor.isServer) {
});
});

it('can delete owned task', () => {
Meteor.call('removeTask', { taskId });
it('can delete owned task', async () => {
await Meteor.callAsync('removeTask', { taskId });

assert.equal(Tasks.find().count(), 0);
});

it("can't delete task if not authenticated", () => {
it("can't delete task if not authenticated", async () => {
mockLoggedUserId(null);
try {
Meteor.call('removeTask', { taskId });
await Meteor.callAsync('removeTask', { taskId });
} catch (error) {
expect(error).to.be.instanceof(Error);
expect(error.reason).to.be.equal('Not authorized.');
}
assert.equal(Tasks.find().count(), 1);
});

it("can't delete task from another owner", () => {
it("can't delete task from another owner", async () => {
mockLoggedUserId(Random.id());
try {
Meteor.call('removeTask', { taskId });
await Meteor.callAsync('removeTask', { taskId });
} catch (error) {
expect(error).to.be.instanceof(Error);
expect(error.reason).to.be.equal('Access denied.');
}
assert.equal(Tasks.find().count(), 1);
});

it('can change the status of a task', () => {
it('can change the status of a task', async () => {
const originalTask = Tasks.findOne(taskId);
Meteor.call('toggleTaskDone', { taskId });
await Meteor.callAsync('toggleTaskDone', { taskId });

const updatedTask = Tasks.findOne(taskId);
assert.notEqual(updatedTask.done, originalTask.done);
});

it("can't change the status of a task from another owner", () => {
it("can't change the status of a task from another owner", async () => {
mockLoggedUserId(Random.id());
const originalTask = Tasks.findOne(taskId);

try {
Meteor.call('toggleTaskDone', { taskId });
await Meteor.callAsync('toggleTaskDone', { taskId });
} catch (error) {
expect(error).to.be.instanceof(Error);
expect(error.reason).to.be.equal('Access denied.');
Expand All @@ -72,20 +72,20 @@ if (Meteor.isServer) {
assert.equal(task.done, originalTask.done);
});

it('can insert new tasks', () => {
it('can insert new tasks', async () => {
const description = 'New Task';
Meteor.call('insertTask', { description });
await Meteor.callAsync('insertTask', { description });

const task = Tasks.findOne({ description });
assert.isNotNull(task);
assert.isTrue(task.description === description);
});

it("can't insert new tasks if not authenticated", () => {
it("can't insert new tasks if not authenticated", async () => {
mockLoggedUserId(null);
const description = 'New Task';
try {
Meteor.call('insertTask', { description });
await Meteor.callAsync('insertTask', { description });
} catch (error) {
expect(error).to.be.instanceof(Error);
expect(error.reason).to.be.equal('Not authorized.');
Expand Down
8 changes: 4 additions & 4 deletions ui/pages/tasks/hooks/use-task-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { Meteor } from 'meteor/meteor';
export function useTaskItem() {
const toast = useToast();

function onMarkAsDone(_id) {
Meteor.call('toggleTaskDone', { taskId: _id });
async function onMarkAsDone(_id) {
await Meteor.callAsync('toggleTaskDone', { taskId: _id });
}

function onDelete(_id) {
async function onDelete(_id) {
try {
Meteor.call('removeTask', { taskId: _id });
await Meteor.callAsync('removeTask', { taskId: _id });
toast({
title: 'Task removed.',
status: 'success',
Expand Down