Add independent roast plan cloning from the plans table
Test and deploy / test-and-deploy (push) Successful in 1m52s
Test and deploy / test-and-deploy (push) Successful in 1m52s
This commit is contained in:
1 parent
393978195c
commit
a9358048ef
5 files changed
+46
-1
No files matched your search
@@ -89,3 +89,12 @@ test("summary search, filters and pagination exclude full telemetry and other ac
|
||||
0,
|
||||
);
|
||||
});
|
||||
|
||||
test('clone creates an independent owned plan without copying roast outcomes or consumption', async () => {
|
||||
const {app,agent}=await setup();const {csrf}=await signup(agent,'[email protected]');const other=request.agent(app);const {csrf:otherCsrf}=await signup(other,'[email protected]');
|
||||
const plan=blankPlan();plan.fields['0.1']='Burundi';plan.fields['4.1']='light';plan.temps.fc.tempC='190';plan.inventory={lotId:'lot',lotLabel:'Burundi lot',consumed:{weightG:500}};plan.afterRoast.cupNotes='Original cup';plan.planActual.fc.actualTime='8:20';
|
||||
const original=(await agent.post('/api/plans').set('x-csrf-token',csrf).send({plan,name:'Fruity'})).body.plan;
|
||||
const route='/api/plans/'+original.id+'/clone';assert.equal((await request(app).post(route)).status,401);assert.equal((await agent.post(route)).status,403);assert.equal((await other.post(route).set('x-csrf-token',otherCsrf)).status,404);assert.equal((await agent.post('/api/plans/not-a-uuid/clone').set('x-csrf-token',csrf)).status,404);
|
||||
const response=await agent.post(route).set('x-csrf-token',csrf);assert.equal(response.status,201);const copy=response.body.plan;assert.notEqual(copy.id,original.id);assert.equal(copy.name,'Fruity (copy)');assert.deepEqual(copy.plan.fields,plan.fields);assert.deepEqual(copy.plan.temps,plan.temps);assert.equal(copy.plan.inventory.lotId,'lot');assert.equal(copy.plan.inventory.consumed,null);assert.deepEqual(copy.plan.afterRoast,blankPlan().afterRoast);assert.deepEqual(copy.plan.planActual,blankPlan().planActual);
|
||||
copy.plan.fields['4.1']='medium';assert.equal((await agent.put('/api/plans/'+copy.id).set('x-csrf-token',csrf).send({plan:copy.plan})).status,200);assert.deepEqual((await agent.get('/api/plans/'+original.id)).body.plan.plan,plan);assert.equal((await other.get('/api/plans/'+copy.id)).status,404);
|
||||
});
|
||||
@@ -286,3 +286,9 @@ test('browser: rejected sync shows the cause and keeps the edited plan open', br
|
||||
await page.locator('#plan-form input[name="0.4"]').fill('550');await page.getByRole('link',{name:'▤ Your plans',exact:true}).click();await page.getByText(/Your sign-in session needs refreshing/).waitFor();assert.ok(page.url().includes('/app?plan='+saved.id));assert.equal((await db.query('SELECT COUNT(*) AS n FROM roast_plans')).rows[0].n,1);
|
||||
const draft=await page.evaluate(()=>JSON.parse(localStorage.getItem(Object.keys(localStorage).find(k=>k.startsWith('roastPlannerPlan.v2:')&&!k.endsWith(':last-user')))));assert.equal(draft.plan.fields['0.4'],'550');
|
||||
});
|
||||
|
||||
test('browser: Clone opens an independent plan whose roast level can change', browserOptions, async t => {
|
||||
const {page,base,create,db,errors}=await session(t);const original=await create(warningPlan(),'Fruit original');await page.goto(base+'/plans');await page.getByRole('button',{name:'Clone Fruit original',exact:true}).click();await page.waitForURL('**/app?plan=*');await page.locator('#header-coffee-name').filter({hasText:'Fruit original (copy)'}).waitFor();
|
||||
const id=new URL(page.url()).searchParams.get('plan');assert.notEqual(id,original.id);await page.locator('#plan-form label').filter({has:page.locator('input[name="4.1"][value="medium"]')}).click();await page.getByRole('link',{name:'▤ Your plans',exact:true}).click();await page.waitForURL('**/plans*');await page.getByRole('link',{name:'Fruit original (copy)',exact:true}).waitFor();
|
||||
const rows=(await db.query('SELECT id,plan FROM roast_plans')).rows;assert.equal(rows.length,2);assert.equal(rows.find(r=>r.id===original.id).plan.fields['4.1'],'light');assert.equal(rows.find(r=>r.id===id).plan.fields['4.1'],'medium');assert.deepEqual(errors,[]);
|
||||
});
|
||||
Reference in new issue
Block a user