Skip to content

Add count and edit commands#8

Open
Sauvage666 wants to merge 2 commits into
mate-academy:mainfrom
Sauvage666:feat/count-command
Open

Add count and edit commands#8
Sauvage666 wants to merge 2 commits into
mate-academy:mainfrom
Sauvage666:feat/count-command

Conversation

@Sauvage666

@Sauvage666 Sauvage666 commented Jun 19, 2026

Copy link
Copy Markdown

Summary

  • Adds node notes.js count — imprime cuántas notas hay (You have N notes., con singular/plural correcto).
  • Adds node notes.js edit <id> <new text> — actualiza el texto de una nota existente.
  • Actualiza el mensaje de ayuda por defecto para incluir ambos comandos.
  • Añade 2 tests de integración para edit (caso exitoso y ID no encontrado).

What changed

notes.js — dos nuevos casos en el switch: count y edit. El caso edit valida que se pasen ID y texto antes de llamar al store, y maneja el caso de ID inexistente sin crashear.

lib/store.js — nueva función edit(id, newText) que busca la nota, devuelve null si no existe, actualiza el texto y persiste. Exportada junto al resto.

tests/notes.test.js — helper withCleanStore para tests de integración con filesystem (setup/teardown limpio). Dos tests nuevos: edición exitosa y null en ID desconocido.

Reviewer notes

  • edit es la única función de store.js que no es pura (toca el filesystem), de ahí el helper de integración en lugar de un test unitario directo.
  • Number(rest[0]) devuelve NaN para input ausente — la validación !id lo cubre porque !NaN === true.
  • El guard !id también rechaza id === 0, que no puede ser un ID válido dado que nextId arranca en 1.

Test plan

  • npm test 5/5 en main antes de cualquier cambio
  • npm test 5/5 en esta rama tras ambos commits
  • node notes.js countYou have 0 notes. en store vacío
  • node notes.js edit 1 nuevo textoUpdated note #1: nuevo texto
  • node notes.js edit 999 xNo note #999 found
  • node notes.js edit (sin args) → mensaje de uso

🤖 Generated with Claude Code

Sauvage666 and others added 2 commits June 19, 2026 23:05
Adds `node notes.js count` which prints "You have N notes." (with
correct singular/plural). Also updates the default help message to
include the new command.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds `node notes.js edit <id> <new text>` to update the text of an
existing note. Guards against missing ID or empty text (usage hint),
unknown IDs (returns null instead of crashing), and updates the help
message. Includes two integration tests for the happy path and the
not-found case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Sauvage666 Sauvage666 changed the title Add count command Add count and edit commands Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant