From 2a48343f6bbae04123acd22f68ffd5e68dce2514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 23 Sep 2024 16:36:43 +0200 Subject: [PATCH] adapt simpletasks for 2.x version --- .meteor/packages | 40 +++--- .meteor/release | 2 +- .meteor/versions | 183 ++++++++++++------------- api/db/migrations.js | 18 +-- api/lib/auth.js | 4 +- api/tasks/tasks.methods.js | 24 ++-- api/tasks/tasks.methods.tests.js | 56 ++++---- api/tasks/tasks.publications.tests.js | 18 +-- ui/pages/tasks/hooks/use-task-item.jsx | 8 +- 9 files changed, 174 insertions(+), 179 deletions(-) diff --git a/.meteor/packages b/.meteor/packages index df2ff1e..b175b5d 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -4,30 +4,30 @@ # 'meteor add' and 'meteor remove' will edit this file for you, # but you can also edit it by hand. -meteor-base@1.5.2 # Packages every Meteor app needs to have -mobile-experience@1.1.2 # Packages for a great mobile UX -mongo@2.0.2 # The database Meteor supports right now -reactive-var@1.0.13 # Reactive variable for tracker +meteor-base@1.5.1 # Packages every Meteor app needs to have +mobile-experience@1.1.1 # Packages for a great mobile UX +mongo@1.16.10 # The database Meteor supports right now +reactive-var@1.0.11 # Reactive variable for tracker -standard-minifier-css@1.9.3 # CSS minifier run for production mode -es5-shim@4.8.1 # ECMAScript 5 compatibility for older browsers -ecmascript@0.16.9 # Enable ECMAScript2015+ syntax in app code -typescript@5.4.3 # Enable TypeScript syntax in .ts and .tsx modules -shell-server@0.6.0 # Server-side component of the `meteor shell` command -hot-module-replacement@0.5.4 # Update client in development without reloading the page +standard-minifier-css@1.9.2 # CSS minifier run for production mode +es5-shim@4.8.0 # ECMAScript 5 compatibility for older browsers +ecmascript@0.16.8 # Enable ECMAScript2015+ syntax in app code +typescript@4.9.5 # Enable TypeScript syntax in .ts and .tsx modules +shell-server@0.5.0 # Server-side component of the `meteor shell` command +hot-module-replacement@0.5.3 # Update client in development without reloading the page -static-html@1.3.3 # Define static page content in .html files -dev-error-overlay@0.1.3 +static-html@1.3.2 # Define static page content in .html files +dev-error-overlay@0.1.2 -accounts-password@3.0.2 -force-ssl@1.1.1 -meteortesting:mocha@3.2.0 +accounts-password@2.4.0 +force-ssl@1.1.0 +meteortesting:mocha jam:easy-schema@1.4.0 quave:migrations -react-meteor-accounts@1.0.3 -react-meteor-data@3.0.0 +react-meteor-accounts@1.0.0 +react-meteor-data@2.7.2 montiapm:agent zodern:standard-minifier-js -accounts-github@1.5.1 -service-configuration@1.3.5 -ddp-rate-limiter@1.2.2 +accounts-github@1.5.0 +service-configuration@1.3.4 +ddp-rate-limiter@1.2.1 diff --git a/.meteor/release b/.meteor/release index c41cba9..5152abe 100644 --- a/.meteor/release +++ b/.meteor/release @@ -1 +1 @@ -METEOR@3.0.3 +METEOR@2.16 diff --git a/.meteor/versions b/.meteor/versions index 98fe798..25fa0c1 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -1,100 +1,99 @@ -accounts-base@3.0.2 -accounts-github@1.5.1 -accounts-oauth@1.4.5 -accounts-password@3.0.2 -allow-deny@2.0.0 -autoupdate@2.0.0 -babel-compiler@7.11.0 -babel-runtime@1.5.2 -base64@1.0.13 -binary-heap@1.0.12 -blaze-tools@2.0.0 -boilerplate-generator@2.0.0 -caching-compiler@2.0.0 -caching-html-compiler@2.0.0 -callback-hook@1.6.0 -check@1.4.2 -core-runtime@1.0.0 -ddp@1.4.2 -ddp-client@3.0.1 -ddp-common@1.4.4 -ddp-rate-limiter@1.2.2 -ddp-server@3.0.1 -dev-error-overlay@0.1.3 -diff-sequence@1.1.3 -dynamic-import@0.7.4 -ecmascript@0.16.9 -ecmascript-runtime@0.8.2 -ecmascript-runtime-client@0.12.2 -ecmascript-runtime-server@0.11.1 -ejson@1.1.4 -email@3.1.0 -es5-shim@4.8.1 -facts-base@1.0.2 -fetch@0.1.5 -force-ssl@1.1.1 -force-ssl-common@1.1.1 -geojson-utils@1.0.12 -github-oauth@1.4.2 -hot-code-push@1.0.5 -hot-module-replacement@0.5.4 -html-tools@2.0.0 -htmljs@2.0.1 -id-map@1.2.0 -inter-process-messaging@0.1.2 +accounts-base@2.2.11 +accounts-github@1.5.0 +accounts-oauth@1.4.4 +accounts-password@2.4.0 +allow-deny@1.1.1 +autoupdate@1.8.0 +babel-compiler@7.10.5 +babel-runtime@1.5.1 +base64@1.0.12 +binary-heap@1.0.11 +blaze-tools@1.1.3 +boilerplate-generator@1.7.2 +caching-compiler@1.2.2 +caching-html-compiler@1.2.1 +callback-hook@1.5.1 +check@1.4.1 +ddp@1.4.1 +ddp-client@2.6.2 +ddp-common@1.4.1 +ddp-rate-limiter@1.2.1 +ddp-server@2.7.1 +dev-error-overlay@0.1.2 +diff-sequence@1.1.2 +dynamic-import@0.7.3 +ecmascript@0.16.8 +ecmascript-runtime@0.8.1 +ecmascript-runtime-client@0.12.1 +ecmascript-runtime-server@0.11.0 +ejson@1.1.3 +email@2.2.6 +es5-shim@4.8.0 +fetch@0.1.4 +force-ssl@1.1.0 +force-ssl-common@1.1.0 +geojson-utils@1.0.11 +github-oauth@1.4.1 +hot-code-push@1.0.4 +hot-module-replacement@0.5.3 +html-tools@1.1.3 +htmljs@1.1.1 +http@1.0.10 +id-map@1.1.1 +inter-process-messaging@0.1.1 jam:easy-schema@1.4.0 -launch-screen@2.0.1 -localstorage@1.2.1 -logging@1.3.5 +launch-screen@2.0.0 +localstorage@1.2.0 +logging@1.3.4 mdg:validation-error@0.5.1 -meteor@2.0.1 -meteor-base@1.5.2 -meteortesting:browser-tests@1.7.0 -meteortesting:mocha@3.2.0 +meteor@1.11.5 +meteor-base@1.5.1 +meteortesting:browser-tests@1.6.0 +meteortesting:mocha@3.1.0-beta300.0 meteortesting:mocha-core@8.3.1-rc300.1 -minifier-css@2.0.0 -minimongo@2.0.1 -mobile-experience@1.1.2 -mobile-status-bar@1.1.1 -modern-browsers@0.1.11 -modules@0.20.1 -modules-runtime@0.13.2 -modules-runtime-hot@0.14.3 -mongo@2.0.2 -mongo-decimal@0.1.4-beta300.7 -mongo-dev-server@1.1.1 -mongo-id@1.0.9 -montiapm:agent@3.0.0-beta.5 -montiapm:meteorx@2.3.1 -npm-mongo@4.17.4 -oauth@3.0.0 -oauth2@1.3.3 -ordered-dict@1.2.0 -promise@1.0.0 +minifier-css@1.6.4 +minimongo@1.9.4 +mobile-experience@1.1.1 +mobile-status-bar@1.1.0 +modern-browsers@0.1.10 +modules@0.20.0 +modules-runtime@0.13.1 +modules-runtime-hot@0.14.2 +mongo@1.16.10 +mongo-decimal@0.1.3 +mongo-dev-server@1.1.0 +mongo-id@1.0.8 +montiapm:agent@2.49.4 +montiapm:meteorx@2.2.0 +npm-mongo@4.17.2 +oauth@2.2.1 +oauth2@1.3.2 +ordered-dict@1.1.0 +promise@0.12.2 quave:migrations@2.0.2 -random@1.2.2 -rate-limit@1.1.2 -react-fast-refresh@0.2.9 +random@1.2.1 +rate-limit@1.1.1 +react-fast-refresh@0.2.8 react-meteor-accounts@1.0.3 -react-meteor-data@3.0.2 -reactive-var@1.0.13 -reload@1.3.2 -retry@1.1.1 -routepolicy@1.1.2 -service-configuration@1.3.5 -sha@1.0.10 -shell-server@0.6.0 -socket-stream-client@0.5.3 -spacebars-compiler@2.0.0 -standard-minifier-css@1.9.3 -static-html@1.3.3 -templating-tools@2.0.0 -tracker@1.3.4 -typescript@5.4.3 -underscore@1.6.4 -url@1.3.3 -webapp@2.0.1 -webapp-hashing@1.1.2 +react-meteor-data@2.7.2 +reactive-var@1.0.12 +reload@1.3.1 +retry@1.1.0 +routepolicy@1.1.1 +service-configuration@1.3.4 +sha@1.0.9 +shell-server@0.5.0 +socket-stream-client@0.5.2 +spacebars-compiler@1.3.1 +standard-minifier-css@1.9.2 +static-html@1.3.2 +templating-tools@1.2.2 +tracker@1.3.3 +typescript@4.9.5 +underscore@1.6.2 +url@1.3.2 +webapp@1.13.8 +webapp-hashing@1.1.1 zodern:caching-minifier@0.5.0 zodern:meteor-package-versions@0.2.2 zodern:standard-minifier-js@5.3.1 diff --git a/api/db/migrations.js b/api/db/migrations.js index 03cfcb5..c16be39 100644 --- a/api/db/migrations.js +++ b/api/db/migrations.js @@ -5,8 +5,8 @@ import { Tasks } from '../tasks/tasks'; Migrations.add({ version: 1, name: 'Add a seed username and password.', - async up() { - await Accounts.createUserAsync({ + up() { + Accounts.createUser({ username: 'fredmaia', password: 'abc123', }); @@ -16,21 +16,21 @@ Migrations.add({ Migrations.add({ version: 2, name: 'Add a few sample tasks.', - async up() { - const user = await Accounts.findUserByUsername('fredmaia'); - await Tasks.insertAsync({ - description: 'Install Node@20', + up() { + const user = Accounts.findUserByUsername('fredmaia'); + Tasks.insert({ + description: 'Install Node@14', done: false, userId: user._id, createdAt: new Date(2024, 1, 1), }); - await Tasks.insertAsync({ - description: 'Install Meteor.js 3.0', + Tasks.insert({ + description: 'Install Meteor.js 2.0', done: false, userId: user._id, createdAt: new Date(2024, 1, 2), }); - await Tasks.insertAsync({ + Tasks.insert({ description: 'Clone this repository', done: false, userId: user._id, diff --git a/api/lib/auth.js b/api/lib/auth.js index 19c6e59..28af471 100644 --- a/api/lib/auth.js +++ b/api/lib/auth.js @@ -17,10 +17,10 @@ export function checkLoggedIn() { * @param {{ taskId: String }} * @throws Will throw an error if user is not logged in or is not the task owner. */ -export async function checkTaskOwner({ taskId }) { +export function checkTaskOwner({ taskId }) { check(taskId, String); checkLoggedIn(); - const task = await Tasks.findOneAsync({ + const task = Tasks.findOne({ _id: taskId, userId: Meteor.userId(), }); diff --git a/api/tasks/tasks.methods.js b/api/tasks/tasks.methods.js index b7c78ee..6a77276 100644 --- a/api/tasks/tasks.methods.js +++ b/api/tasks/tasks.methods.js @@ -10,9 +10,9 @@ import { Tasks } from './tasks'; @function insertTask @param {Object} taskData - The task data. @param {string} taskData.description - The description of the task. - @returns {Promise} - The ID of the inserted task. + @returns {string} - The ID of the inserted task. */ -async function insertTask({ description }) { +function insertTask({ description }) { check(description, String); checkLoggedIn(); const task = { @@ -21,7 +21,7 @@ async function insertTask({ description }) { userId: Meteor.userId(), createdAt: new Date(), }; - return Tasks.insertAsync(task); + return Tasks.insert(task); } /** @@ -30,12 +30,12 @@ async function insertTask({ description }) { @function removeTask @param {Object} taskData - The task data. @param {string} taskData.taskId - The ID of the task to remove. - @returns {Promise} + @returns {number} */ -async function removeTask({ taskId }) { +function removeTask({ taskId }) { check(taskId, String); - await checkTaskOwner({ taskId }); - return Tasks.removeAsync(taskId); + checkTaskOwner({ taskId }); + return Tasks.remove(taskId); } /** @@ -44,13 +44,13 @@ async function removeTask({ taskId }) { @function toggleTaskDone @param {Object} taskData - The task data. @param {string} taskData.taskId - The ID of the task to toggle. - @returns {Promise} + @returns {number} */ -async function toggleTaskDone({ taskId }) { +function toggleTaskDone({ taskId }) { check(taskId, String); - await checkTaskOwner({ taskId }); - const task = await Tasks.findOneAsync(taskId); - return Tasks.updateAsync({ _id: taskId }, { $set: { done: !task.done } }); + checkTaskOwner({ taskId }); + const task = Tasks.findOne(taskId); + return Tasks.update({ _id: taskId }, { $set: { done: !task.done } }); } Meteor.methods({ insertTask, removeTask, toggleTaskDone }); diff --git a/api/tasks/tasks.methods.tests.js b/api/tasks/tasks.methods.tests.js index de32363..cdd4dbd 100644 --- a/api/tasks/tasks.methods.tests.js +++ b/api/tasks/tasks.methods.tests.js @@ -11,90 +11,86 @@ if (Meteor.isServer) { const userId = Random.id(); let taskId; - beforeEach(async () => { + beforeEach(() => { mockLoggedUserId(userId); - await Tasks.removeAsync({}).catch((error) => { - console.error(error); - }); - taskId = await Tasks.insertAsync({ + Tasks.remove({}); + taskId = Tasks.insert({ description: 'Test Task', done: false, createdAt: new Date(), userId, - }).catch((error) => { - console.error(error); }); }); - it('can delete owned task', async () => { - await Meteor.callAsync('removeTask', { taskId }); + it('can delete owned task', () => { + Meteor.call('removeTask', { taskId }); - assert.equal(await Tasks.find().countAsync(), 0); + assert.equal(Tasks.find().count(), 0); }); - it("can't delete task if not authenticated", async () => { + it("can't delete task if not authenticated", () => { mockLoggedUserId(null); try { - await Meteor.callAsync('removeTask', { taskId }); + Meteor.call('removeTask', { taskId }); } catch (error) { expect(error).to.be.instanceof(Error); expect(error.reason).to.be.equal('Not authorized.'); } - assert.equal(await Tasks.find().countAsync(), 1); + assert.equal(Tasks.find().count(), 1); }); - it("can't delete task from another owner", async () => { + it("can't delete task from another owner", () => { mockLoggedUserId(Random.id()); try { - await Meteor.callAsync('removeTask', { taskId }); + Meteor.call('removeTask', { taskId }); } catch (error) { expect(error).to.be.instanceof(Error); expect(error.reason).to.be.equal('Access denied.'); } - assert.equal(await Tasks.find().countAsync(), 1); + assert.equal(Tasks.find().count(), 1); }); - it('can change the status of a task', async () => { - const originalTask = await Tasks.findOneAsync(taskId); - await Meteor.callAsync('toggleTaskDone', { taskId }); + it('can change the status of a task', () => { + const originalTask = Tasks.findOne(taskId); + Meteor.call('toggleTaskDone', { taskId }); - const updatedTask = await Tasks.findOneAsync(taskId); + const updatedTask = Tasks.findOne(taskId); assert.notEqual(updatedTask.done, originalTask.done); }); - it("can't change the status of a task from another owner", async () => { + it("can't change the status of a task from another owner", () => { mockLoggedUserId(Random.id()); - const originalTask = await Tasks.findOneAsync(taskId); + const originalTask = Tasks.findOne(taskId); try { - await Meteor.callAsync('toggleTaskDone', { taskId }); + Meteor.call('toggleTaskDone', { taskId }); } catch (error) { expect(error).to.be.instanceof(Error); expect(error.reason).to.be.equal('Access denied.'); } - const task = await Tasks.findOneAsync(taskId); + const task = Tasks.findOne(taskId); assert.equal(task.done, originalTask.done); }); - it('can insert new tasks', async () => { + it('can insert new tasks', () => { const description = 'New Task'; - await Meteor.callAsync('insertTask', { description }); + Meteor.call('insertTask', { description }); - const task = await Tasks.findOneAsync({ description }); + const task = Tasks.findOne({ description }); assert.isNotNull(task); assert.isTrue(task.description === description); }); - it("can't insert new tasks if not authenticated", async () => { + it("can't insert new tasks if not authenticated", () => { mockLoggedUserId(null); const description = 'New Task'; try { - await Meteor.callAsync('insertTask', { description }); + Meteor.call('insertTask', { description }); } catch (error) { expect(error).to.be.instanceof(Error); expect(error.reason).to.be.equal('Not authorized.'); } - const task = await Tasks.findOneAsync({ description }); + const task = Tasks.findOne({ description }); assert.isUndefined(task); }); }); diff --git a/api/tasks/tasks.publications.tests.js b/api/tasks/tasks.publications.tests.js index b37befe..04e17bc 100644 --- a/api/tasks/tasks.publications.tests.js +++ b/api/tasks/tasks.publications.tests.js @@ -15,32 +15,32 @@ describe('Tasks', () => { userId, }; - beforeEach(async () => { + beforeEach(() => { mockLoggedUserId(userId); - await Tasks.removeAsync({}); - await Tasks.insertAsync(originalTask); + Tasks.remove({}); + Tasks.insert(originalTask); }); - it('should return tasks from the authenticated user', async () => { + it('should return tasks from the authenticated user', () => { const publication = getMeteorPublication('tasksByLoggedUser'); - const tasks = await publication.fetchAsync(); + const tasks = publication.fetch(); expect(tasks.length).to.be.equal(1); expect(tasks[0].description).to.be.equal(originalTask.description); }); - it('should not return any task to the user who does not have any', async () => { + it('should not return any task to the user who does not have any', () => { mockLoggedUserId(Random.id()); const publication = getMeteorPublication('tasksByLoggedUser'); - const tasks = await publication.fetchAsync(); + const tasks = publication.fetch(); expect(tasks.length).to.be.equal(0); }); - it('should not return any task if not authenticated', async () => { + it('should not return any task if not authenticated', () => { mockLoggedUserId(null); const publication = getMeteorPublication('tasksByLoggedUser'); - const tasks = await publication.fetchAsync(); + const tasks = publication.fetch(); expect(tasks.length).to.be.equal(0); }); diff --git a/ui/pages/tasks/hooks/use-task-item.jsx b/ui/pages/tasks/hooks/use-task-item.jsx index 87d7da5..68bfa76 100644 --- a/ui/pages/tasks/hooks/use-task-item.jsx +++ b/ui/pages/tasks/hooks/use-task-item.jsx @@ -4,13 +4,13 @@ import { Meteor } from 'meteor/meteor'; export function useTaskItem() { const toast = useToast(); - async function onMarkAsDone(_id) { - await Meteor.callAsync('toggleTaskDone', { taskId: _id }); + function onMarkAsDone(_id) { + Meteor.call('toggleTaskDone', { taskId: _id }); } - async function onDelete(_id) { + function onDelete(_id) { try { - await Meteor.callAsync('removeTask', { taskId: _id }); + Meteor.call('removeTask', { taskId: _id }); toast({ title: 'Task removed.', status: 'success',