{"schemaVersion":1,"contentVersion":"3.4.0","id":"intermediate.20","languages":{"javascript":{"id":"intermediate.20","title":"Checkpoint: brackets, blocks and lines","moduleName":"Boundaries and reusable text","tips":"","concept":"<p class=\"lead\">Make three changes in each of three real files: an API module, a config and a test.</p><p><strong>Before this lesson:</strong> Text objects for brackets, %, deleting to a search, registers, paragraphs and the jump list.</p><p>You choose the commands here. Look at the shape of the code first: a change inside brackets is ci( or di{, a call with nested brackets goes with d%, a block between blank lines is a paragraph, and J joins a line that was split. Help is still there if you need it, and your result notes whether you used it.</p><h3>Example</h3><p>Before you start, read the task and find every line that changes. Check the whole result when you're done.</p><p>Try without hints first. Open help if you need it.</p>","teaches":[],"introduces":[],"constraints":[],"drills":[{"task":"The API knows the customer from the session and pages by itself now: make the query just <code>{ limit: 50 }</code>. It drops drafts too, so remove the <code>.filter(…)</code> call. And cancelling is a <code>PATCH</code> now, not a <code>POST</code>. You can use any commands.","hint":"Look at the shape first: ci( and di{ work from inside the brackets, % finds a bracket's partner, dap takes a paragraph and J joins a line that was split.","mode":"jsx","start":"import { request } from \"./http\";\n\n// Orders for the account page, newest first.\nexport function listOrders(customerId) {\n  return request(\"GET\", \"/orders\", { customer: customerId, page: 1, perPage: 20 })\n    .then((response) => response.json())\n    .then((body) => body.orders.filter((order) => order.status !== \"draft\"));\n}\n\nexport function cancelOrder(orderId) {\n  return request(\"POST\", `/orders/${orderId}/cancel`);\n}","startCursor":{"line":0,"ch":0},"paths":[{"keys":["5","G","f","{","w","c","f","0","limit: 50","<Esc>","2","j","F",".","d","%","4","j","F","\"","c","b","PATCH","<Esc>"],"tier":"idiomatic","technique":"bracket-match","core":["bracket-match"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"import { request } from \"./http\";\n\n// Orders for the account page, newest first.\nexport function listOrders(customerId) {\n  return request(\"GET\", \"/orders\", { limit: 50 })\n    .then((response) => response.json())\n    .then((body) => body.orders);\n}\n\nexport function cancelOrder(orderId) {\n  return request(\"PATCH\", `/orders/${orderId}/cancel`);\n}","language":"javascript","evidence":"checkpoint","canonicalKey":"intermediate.20#0","canonicalFingerprint":"zxbhwp"},{"task":"Run the dev server on port <code>3001</code>, and empty the proxy settings: the API sends its own CORS headers now. Then indent <code>outDir</code> like the line below it. You can use any commands.","hint":"Look at the shape first: ci( and di{ work from inside the brackets, % finds a bracket's partner, dap takes a paragraph and J joins a line that was split.","mode":"jsx","start":"import react from \"@vitejs/plugin-react\";\n\n// Build settings for the storefront.\nexport default {\n  plugins: [react()],\n  server: { port: 3000, proxy: { \"/api\": \"http://localhost:8000\" } },\n  build: {\n  outDir: \"dist\",\n    sourcemap: true,\n  },\n};","startCursor":{"line":0,"ch":0},"paths":[{"keys":["6","G","f","3","e","r","1","f","{","d","i","{","2","j",">",">"],"tier":"idiomatic","technique":"textobject:i{","core":["textobject:i{","operator:>"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"import react from \"@vitejs/plugin-react\";\n\n// Build settings for the storefront.\nexport default {\n  plugins: [react()],\n  server: { port: 3001, proxy: {} },\n  build: {\n    outDir: \"dist\",\n    sourcemap: true,\n  },\n};","language":"javascript","evidence":"checkpoint","canonicalKey":"intermediate.20#1","canonicalFingerprint":"1fnd7o4"},{"task":"The skipped shipping test is out of date: delete it. Join the two lines of <code>cart</code> in the last test, and use a <code>cup</code> there instead of a <code>mug</code>. You can use any commands.","hint":"Look at the shape first: ci( and di{ work from inside the brackets, % finds a bracket's partner, dap takes a paragraph and J joins a line that was split.","mode":"jsx","start":"import { addItem, cartTotal, emptyCart } from \"./cart\";\n\ndescribe(\"cartTotal\", () => {\n  it(\"is zero for an empty cart\", () => expect(cartTotal(emptyCart())).toBe(0));\n\n  it.skip(\"adds shipping under 50 euros\", () => {\n    expect(cartTotal(addItem(emptyCart(), { sku: \"tray\", cents: 1200 }))).toBe(1695);\n  });\n\n  it(\"adds up the items\", () => {\n    const cart = addItem(addItem(emptyCart(), { sku: \"mug\", cents: 1200 }),\n      { sku: \"tea\", cents: 650 });\n    expect(cartTotal(cart)).toBe(1850);\n  });\n});","startCursor":{"line":0,"ch":0},"paths":[{"keys":["6","G","d","a","p","j","J","F","\"","b","c","w","cup","<Esc>"],"tier":"idiomatic","technique":"textobject:ap","core":["textobject:ap","join"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"import { addItem, cartTotal, emptyCart } from \"./cart\";\n\ndescribe(\"cartTotal\", () => {\n  it(\"is zero for an empty cart\", () => expect(cartTotal(emptyCart())).toBe(0));\n\n  it(\"adds up the items\", () => {\n    const cart = addItem(addItem(emptyCart(), { sku: \"cup\", cents: 1200 }), { sku: \"tea\", cents: 650 });\n    expect(cartTotal(cart)).toBe(1850);\n  });\n});","language":"javascript","evidence":"checkpoint","canonicalKey":"intermediate.20#2","canonicalFingerprint":"93fd5v"}]},"python":{"id":"intermediate.20","title":"Checkpoint: brackets, blocks and lines","moduleName":"Boundaries and reusable text","tips":"","concept":"<p class=\"lead\">Make three changes in each of three real files: an API module, a config and a test.</p><p><strong>Before this lesson:</strong> Text objects for brackets, %, deleting to a search, registers, paragraphs and the jump list.</p><p>You choose the commands here. Look at the shape of the code first: a change inside brackets is ci( or di{, a call with nested brackets goes with d%, a block between blank lines is a paragraph, and J joins a line that was split. Help is still there if you need it, and your result notes whether you used it.</p><h3>Example</h3><p>Before you start, read the task and find every line that changes. Check the whole result when you're done.</p><p>Try without hints first. Open help if you need it.</p>","teaches":[],"introduces":[],"constraints":[],"drills":[{"task":"The API pages by itself now: make <code>params</code> just <code>{\"limit\": 50}</code>, and add <code>timeout=5,</code> on its own line below it. Cancelling is a <code>patch</code> now, not a <code>post</code>. You can use any commands.","hint":"Look at the shape first: ci( and di{ work from inside the brackets, % finds a bracket's partner, dap takes a paragraph and J joins a line that was split.","mode":"python","start":"import requests\n\nfrom shop.conf import api\n\n\ndef list_orders(customer_id):\n    response = requests.get(\n        api.url(\"/orders\"),\n        params={\"customer\": customer_id, \"page\": 1, \"per_page\": 20},\n    )\n    return response.json()[\"orders\"]\n\n\ndef cancel_order(order_id):\n    return requests.post(api.url(f\"/orders/{order_id}/cancel\"))","startCursor":{"line":0,"ch":0},"paths":[{"keys":["9","G","f","{","c","i","{","\"limit\": 50","<Esc>","o","timeout=5,","<Esc>","G","f",".","w","c","w","patch","<Esc>"],"tier":"idiomatic","technique":"textobject:i{","core":["textobject:i{"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"import requests\n\nfrom shop.conf import api\n\n\ndef list_orders(customer_id):\n    response = requests.get(\n        api.url(\"/orders\"),\n        params={\"limit\": 50},\n        timeout=5,\n    )\n    return response.json()[\"orders\"]\n\n\ndef cancel_order(order_id):\n    return requests.patch(api.url(f\"/orders/{order_id}/cancel\"))","language":"python","evidence":"checkpoint","canonicalKey":"intermediate.20#0","canonicalFingerprint":"zxbhwp"},{"task":"Use Django's default cache on your own machine: empty the settings of the <code>\"default\"</code> cache. Indent the <code>INSTALLED_APPS</code> line two more spaces, into the <code>if</code> block, and run the server on <code>8001</code>. You can use any commands.","hint":"Look at the shape first: ci( and di{ work from inside the brackets, % finds a bracket's partner, dap takes a paragraph and J joins a line that was split.","mode":"python","start":"\"\"\"Settings for running the shop on a laptop.\"\"\"\nfrom .common import *  # noqa: F403\n\nDEBUG = env.bool(\"DEBUG\", default=True)  # noqa: F405\nALLOWED_HOSTS = [\"localhost\", \"shop.test\"]\nCACHES = {\"default\": {\"BACKEND\": \"django_redis.cache.RedisCache\", \"LOCATION\": \"redis://localhost:6379/1\"}}\n\nif DEBUG:\n  INSTALLED_APPS += [\"debug_toolbar\", \"django_extensions\"]  # noqa: F405\n\nRUNSERVER_PORT = 8000","startCursor":{"line":0,"ch":0},"paths":[{"keys":["6","G","$","h","d","i","{","3","j",">",">","G","$","r","1"],"tier":"idiomatic","technique":"textobject:i{","core":["textobject:i{","operator:>"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"\"\"\"Settings for running the shop on a laptop.\"\"\"\nfrom .common import *  # noqa: F403\n\nDEBUG = env.bool(\"DEBUG\", default=True)  # noqa: F405\nALLOWED_HOSTS = [\"localhost\", \"shop.test\"]\nCACHES = {\"default\": {}}\n\nif DEBUG:\n    INSTALLED_APPS += [\"debug_toolbar\", \"django_extensions\"]  # noqa: F405\n\nRUNSERVER_PORT = 8001","language":"python","evidence":"checkpoint","canonicalKey":"intermediate.20#1","canonicalFingerprint":"1fnd7o4"},{"task":"The skipped shipping test is out of date: delete it. Join the two lines of <code>cart</code> in the last test, and use a <code>cup</code> there instead of a <code>mug</code>. You can use any commands.","hint":"Look at the shape first: ci( and di{ work from inside the brackets, % finds a bracket's partner, dap takes a paragraph and J joins a line that was split.","mode":"python","start":"from pytest import mark\n\nfrom shop.cart import add_item, cart_total, empty_cart\n\n\n@mark.skip(reason=\"waiting for the new shipping rules\")\ndef test_shipping_under_50_euros():\n    assert cart_total(add_item(empty_cart(), sku=\"tray\", cents=1200)) == 1695\n\n\ndef test_adds_up_the_items():\n    cart = add_item(add_item(empty_cart(), sku=\"mug\", cents=1200),\n                    sku=\"tea\", cents=650)\n    assert cart_total(cart) == 1850","startCursor":{"line":0,"ch":0},"paths":[{"keys":["7","G","d","a","p","j","J","F","\"","b","c","w","cup","<Esc>"],"tier":"idiomatic","technique":"textobject:ap","core":["textobject:ap","join"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"from pytest import mark\n\nfrom shop.cart import add_item, cart_total, empty_cart\n\n\ndef test_adds_up_the_items():\n    cart = add_item(add_item(empty_cart(), sku=\"cup\", cents=1200), sku=\"tea\", cents=650)\n    assert cart_total(cart) == 1850","language":"python","evidence":"checkpoint","canonicalKey":"intermediate.20#2","canonicalFingerprint":"93fd5v"}]},"text":{"id":"intermediate.20","title":"Checkpoint: brackets, blocks and lines","moduleName":"Boundaries and reusable text","tips":"","concept":"<p class=\"lead\">Make three changes in each of three real files: an API module, a config and a test.</p><p><strong>Before this lesson:</strong> Text objects for brackets, %, deleting to a search, registers, paragraphs and the jump list.</p><p>You choose the commands here. Look at the shape of the code first: a change inside brackets is ci( or di{, a call with nested brackets goes with d%, a block between blank lines is a paragraph, and J joins a line that was split. Help is still there if you need it, and your result notes whether you used it.</p><h3>Example</h3><p>Before you start, read the task and find every line that changes. Check the whole result when you're done.</p><p>Try without hints first. Open help if you need it.</p>","teaches":[],"introduces":[],"constraints":[],"drills":[{"task":"Finance wants net revenue: sum <code>net_revenue</code> instead of <code>total_cents</code>. Count only <code>'captured'</code> orders, and show only the ten biggest countries: add <code>LIMIT 10</code> before the semicolon. You can use any commands.","hint":"Look at the shape first: ci( and di{ work from inside the brackets, % finds a bracket's partner, dap takes a paragraph and J joins a line that was split.","mode":"text/plain","start":"-- Revenue per country for last month, for the finance report.\nSELECT country, SUM(total_cents) AS revenue, COUNT(*) AS orders\nFROM orders\nWHERE status IN ('paid', 'shipped', 'delivered', 'refunded')\n  AND placed_at >= DATE_TRUNC('month', NOW() - INTERVAL '1 month')\n  AND placed_at < DATE_TRUNC('month', NOW())\nGROUP BY country\nORDER BY revenue DESC;","startCursor":{"line":0,"ch":0},"paths":[{"keys":["j","%","c","b","net_revenue","<Esc>","2","j","c","i","(","'captured'","<Esc>","G","$","i"," LIMIT 10","<Esc>"],"tier":"idiomatic","technique":"textobject:i(","core":["textobject:i("],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"-- Revenue per country for last month, for the finance report.\nSELECT country, SUM(net_revenue) AS revenue, COUNT(*) AS orders\nFROM orders\nWHERE status IN ('captured')\n  AND placed_at >= DATE_TRUNC('month', NOW() - INTERVAL '1 month')\n  AND placed_at < DATE_TRUNC('month', NOW())\nGROUP BY country\nORDER BY revenue DESC LIMIT 10;","language":"text","evidence":"checkpoint","canonicalKey":"intermediate.20#0","canonicalFingerprint":"zxbhwp"},{"task":"Run the shop on port <code>3001</code> on your machine and keep <code>3000</code> inside the container. Empty the <code>environment</code> map, which comes from <code>.env</code> now, and indent <code>image: postgres:17</code> under <code>db</code>. You can use any commands.","hint":"Look at the shape first: ci( and di{ work from inside the brackets, % finds a bracket's partner, dap takes a paragraph and J joins a line that was split.","mode":"text/plain","start":"# The shop and its database, for working on your own machine.\nservices:\n  shop:\n    image: northwind/shop:4.3.0\n    ports: [\"3000:3000\"]\n    environment: { NODE_ENV: development, DEBUG: \"1\", SHOP_ENV: local }\n    depends_on: [db]\n  db:\n  image: postgres:17\n    volumes: [\"db-data:/var/lib/postgresql/data\"]","startCursor":{"line":0,"ch":0},"paths":[{"keys":["5","G","f","3","e","r","1","j","$","d","i","{","3","j",">",">"],"tier":"idiomatic","technique":"textobject:i{","core":["textobject:i{","operator:>"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"# The shop and its database, for working on your own machine.\nservices:\n  shop:\n    image: northwind/shop:4.3.0\n    ports: [\"3001:3000\"]\n    environment: {}\n    depends_on: [db]\n  db:\n    image: postgres:17\n    volumes: [\"db-data:/var/lib/postgresql/data\"]","language":"text","evidence":"checkpoint","canonicalKey":"intermediate.20#1","canonicalFingerprint":"1fnd7o4"},{"task":"Join the two lines of the second sentence. The Christmas returns paragraph is over: delete it. And refunds take <code>three</code> working days now. You can use any commands.","hint":"Look at the shape first: ci( and di{ work from inside the brackets, % finds a bracket's partner, dap takes a paragraph and J joins a line that was split.","mode":"text/plain","start":"# Returns\n\nYou can return anything within 30 days of delivery.\nPrint the label from your account and drop the parcel\nat any post office.\n\nChristmas orders can be returned until 31 January, even\nif the 30 days have passed. This only applies to orders\nplaced in December.\n\nRefunds take five working days. They go back to the card you paid with.","startCursor":{"line":0,"ch":0},"paths":[{"keys":["4","G","J","2","j","d","a","p","w","w","c","w","three","<Esc>"],"tier":"idiomatic","technique":"textobject:ap","core":["textobject:ap","join"],"note":"This is a clean route with what you've learned so far. Any other way that gets the same result is fine too."}],"target":"# Returns\n\nYou can return anything within 30 days of delivery.\nPrint the label from your account and drop the parcel at any post office.\n\nRefunds take three working days. They go back to the card you paid with.","language":"text","evidence":"checkpoint","canonicalKey":"intermediate.20#2","canonicalFingerprint":"93fd5v"}]}},"concepts":{"javascript":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Text objects for brackets, %, deleting to a search, registers, paragraphs and the jump list.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Make three changes in each of three real files: an API module, a config and a test.</p><p>You choose the commands here. Look at the shape of the code first: a change inside brackets is ci( or di{, a call with nested brackets goes with d%, a block between blank lines is a paragraph, and J joins a line that was split. Help is still there if you need it, and your result notes whether you used it.</p><h2 class=\"prose-subhead\">Example</h2><p>Before you start, read the task and find every line that changes. Check the whole result when you're done.</p><p>Try without hints first. Open help if you need it.</p></div></details>"},"python":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Text objects for brackets, %, deleting to a search, registers, paragraphs and the jump list.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Make three changes in each of three real files: an API module, a config and a test.</p><p>You choose the commands here. Look at the shape of the code first: a change inside brackets is ci( or di{, a call with nested brackets goes with d%, a block between blank lines is a paragraph, and J joins a line that was split. Help is still there if you need it, and your result notes whether you used it.</p><h2 class=\"prose-subhead\">Example</h2><p>Before you start, read the task and find every line that changes. Check the whole result when you're done.</p><p>Try without hints first. Open help if you need it.</p></div></details>"},"text":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Text objects for brackets, %, deleting to a search, registers, paragraphs and the jump list.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Make three changes in each of three real files: an API module, a config and a test.</p><p>You choose the commands here. Look at the shape of the code first: a change inside brackets is ci( or di{, a call with nested brackets goes with d%, a block between blank lines is a paragraph, and J joins a line that was split. Help is still there if you need it, and your result notes whether you used it.</p><h2 class=\"prose-subhead\">Example</h2><p>Before you start, read the task and find every line that changes. Check the whole result when you're done.</p><p>Try without hints first. Open help if you need it.</p></div></details>"}}}