Download pool/shard001/JavaScript/0006002_update.test.js from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 3.33 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/JavaScript/0006002_update.test.js
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard001/JavaScript/0006002_update.test.js
-
curl -L -o 0006002_update.test.js https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/JavaScript/0006002_update.test.js
3.33 kB
| describe('update', function () { | |
| it('should update', function () { | |
| var Test = this | |
| setTimeout(function () { | |
| Test.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(Test.p1)) | |
| }, 30) | |
| return Test.adapter.update(Test.Post, 1, { author: 'John', age: 30 }) | |
| .then(function (data) { | |
| Test.assert.equal(1, Test.requests.length) | |
| Test.assert.equal(Test.requests[0].url, 'api/posts/1') | |
| Test.assert.equal(Test.requests[0].method, 'PUT') | |
| Test.assert.equal(Test.requests[0].requestBody, JSON.stringify({ author: 'John', age: 30 })) | |
| Test.assert.deepEqual(data, Test.p1, 'post 5 should have been updated') | |
| setTimeout(function () { | |
| Test.requests[1].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(Test.p1)) | |
| }, 30) | |
| return Test.adapter.update(Test.Post, 1, { author: 'John', age: 30 }, { basePath: 'api2' }) | |
| }) | |
| .then(function (data) { | |
| Test.assert.equal(2, Test.requests.length) | |
| Test.assert.equal(Test.requests[1].url, 'api2/posts/1') | |
| Test.assert.equal(Test.requests[1].method, 'PUT') | |
| Test.assert.equal(Test.requests[1].requestBody, JSON.stringify({ author: 'John', age: 30 })) | |
| Test.assert.deepEqual(data, Test.p1, 'post 5 should have been updated') | |
| }) | |
| }) | |
| it('should send nested relations', function () { | |
| var Test = this | |
| var JSData = Test.JSData | |
| var store = new JSData.Container() | |
| store.registerAdapter('http', Test.adapter, { default: true }) | |
| store.defineMapper('user', { | |
| relations: { | |
| hasMany: { | |
| post: { | |
| localField: 'posts', | |
| foreignKey: 'userId' | |
| }, | |
| address: { | |
| localField: 'addresses', | |
| foreignKey: 'userId' | |
| } | |
| } | |
| } | |
| }) | |
| store.defineMapper('post', { | |
| relations: { | |
| belongsTo: { | |
| user: { | |
| localField: 'user', | |
| foreignKey: 'userId' | |
| } | |
| } | |
| } | |
| }) | |
| store.defineMapper('address', { | |
| relations: { | |
| belongsTo: { | |
| user: { | |
| localField: 'user', | |
| foreignKey: 'userId' | |
| } | |
| } | |
| } | |
| }) | |
| setTimeout(function () { | |
| Test.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ | |
| id: 1, | |
| posts: [ | |
| { | |
| id: 2, | |
| userId: 1 | |
| } | |
| ] | |
| })) | |
| }, 30) | |
| return store.update('user', 1, { | |
| id: 1, | |
| posts: [ | |
| { | |
| id: 2, | |
| userId: 1 | |
| } | |
| ], | |
| addresses: [ | |
| { | |
| id: 3, | |
| userId: 1 | |
| } | |
| ] | |
| }, { with: ['posts'] }) | |
| .then(function (data) { | |
| Test.assert.equal(1, Test.requests.length) | |
| Test.assert.equal(Test.requests[0].url, 'user/1') | |
| Test.assert.equal(Test.requests[0].method, 'PUT') | |
| Test.assert.equal(Test.requests[0].requestBody, JSON.stringify({ | |
| id: 1, | |
| posts: [ | |
| { | |
| id: 2, | |
| userId: 1 | |
| } | |
| ] | |
| })) | |
| Test.assert.deepEqual(data, { | |
| id: 1, | |
| posts: [ | |
| { | |
| id: 2, | |
| userId: 1 | |
| } | |
| ] | |
| }) | |
| }) | |
| }) | |
| }) | |