{"action":"created","comment":{"url":"https://api.github.com/repos/sgmap/api-communes/pulls/comments/67525980","id":67525980,"diff_hunk":"@@ -0,0 +1,228 @@\n+/* eslint-env mocha */\n+const expect = require('expect.js');\n+const { initFields, initFormat, formatOne } = require('../lib/helpers');\n+\n+describe('helpers', function () {\n+\n+  describe('initFields()', function () {\n+    describe('constructor', () => {\n+      describe('no params', () => {\n+        it('should throw an error', () => {\n+          expect(() => initFields()).to.throwError();\n+        });\n+      });\n+      describe('with base and default params', () => {\n+        it('should success', () => {\n+          expect(() => initFields({ base: ['a', 'b'], default: ['a', 'b', 'c'] })).not.to.throwError();\n+        });\n+      });\n+    });\n+\n+    describe('instance', () => {\n+      function runTestCase(reqParams, expectedFields, done) {\n+        const req = { query: reqParams.query ? reqParams.query : {} };\n+        initFields({\n+          default: ['a', 'b', 'c', 'd'],\n+          base: ['a', 'b'],\n+        })(req, undefined, function (err) {\n+          expect(err).to.be(undefined);\n+          expect(req.fields).to.be.a(Set);\n+          expect(Array.from(req.fields).sort()).to.eql(expectedFields.sort());\n+          done();\n+        });\n+      }\n+\n+      it('empty request should return default fields', function (done) {\n+        runTestCase({}, ['a', 'b', 'c', 'd'], done);\n+      });\n+\n+      it('fields should be read from query', function (done) {\n+        runTestCase(\n+          { query: { fields: 'a,b,x' } },\n+          ['a', 'b', 'x'],\n+          done\n+        );\n+      });\n+\n+      it('base fields should always be present', function (done) {\n+        runTestCase(\n+          { query: { fields: 'x,y,z' } },\n+          ['a', 'b', 'x', 'y', 'z'],\n+          done\n+        );\n+      });\n+    });\n+  });\n+\n+  describe('initFormat()', function () {\n+    describe('constructor', () => {\n+      describe('no params', () => {\n+        it('should success', () => {\n+          expect(() => initFormat()).not.to.throwError();\n+        });\n+      });\n+      describe('geometries only', () => {\n+        it('should throw an error', () => {\n+          expect(() => initFormat({ geometries: ['a', 'b'] })).to.throwError();\n+        });\n+      });\n+      describe('geometries and defaultGeometry not in geometries', () => {\n+        it('should throw an error', () => {\n+          expect(() => initFormat({ geometries: ['a', 'b'], defaultGeometry: 'x' })).to.throwError();\n+        });\n+      });\n+      describe('geometries and defaultGeometry in geometries', () => {\n+        it('should success', () => {\n+          expect(() => initFormat({ geometries: ['a', 'b'], defaultGeometry: 'a' })).not.to.throwError();\n+        });\n+      });\n+    });\n+\n+    describe('instance', () => {\n+      describe('entities without geometries', () => {\n+        let instance;\n+        beforeEach(() => instance = initFormat());\n+\n+        it('should set json as default format', function (done) {\n+          const req = { query: {}, fields: new Set() };\n+          instance(req, undefined, function (err) {\n+            expect(err).to.be(undefined);\n+            expect(req.outputFormat).to.be('json');\n+            done();\n+          });\n+        });\n+\n+        it('should accept json format', function (done) {\n+          const req = { query: { format: 'json' }, fields: new Set() };\n+          instance(req, undefined, function (err) {\n+            expect(err).to.be(undefined);\n+            expect(req.outputFormat).to.be('json');\n+            done();\n+          });\n+        });\n+\n+        it('should not accept geojson format', function (done) {\n+          const req = { query: { format: 'geojson' }, fields: new Set() };\n+          instance(req, undefined, function (err) {\n+            expect(err).to.be(undefined);\n+            expect(req.outputFormat).to.be('json');\n+            done();\n+          });\n+        });\n+      });\n+      describe('entities with geometries', () => {\n+        let instance;\n+        beforeEach(() => instance = initFormat({ geometries: ['a', 'b'], defaultGeometry: 'a' }));\n+\n+        it('should set json as default format', function (done) {\n+          const req = { query: {}, fields: new Set() };\n+          instance(req, undefined, function (err) {\n+            expect(err).to.be(undefined);\n+            expect(req.outputFormat).to.be('json');\n+            done();\n+          });\n+        });\n+\n+        ['json', 'geojson'].forEach(function (format) {\n+          it(format + ' should accept ' + format + ' format', function (done) {","path":"test/helpers.js","position":127,"original_position":127,"commit_id":"17baa6786ba3b8e5df3e3e48eb84648cec50baed","original_commit_id":"dd0b203fe56638d224af6de52e11135f7b58e160","user":{"login":"jdesboeufs","id":1231232,"avatar_url":"https://avatars.githubusercontent.com/u/1231232?v=3","gravatar_id":"","url":"https://api.github.com/users/jdesboeufs","html_url":"https://github.com/jdesboeufs","followers_url":"https://api.github.com/users/jdesboeufs/followers","following_url":"https://api.github.com/users/jdesboeufs/following{/other_user}","gists_url":"https://api.github.com/users/jdesboeufs/gists{/gist_id}","starred_url":"https://api.github.com/users/jdesboeufs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdesboeufs/subscriptions","organizations_url":"https://api.github.com/users/jdesboeufs/orgs","repos_url":"https://api.github.com/users/jdesboeufs/repos","events_url":"https://api.github.com/users/jdesboeufs/events{/privacy}","received_events_url":"https://api.github.com/users/jdesboeufs/received_events","type":"User","site_admin":false},"body":"Can you explain?","created_at":"2016-06-17T15:12:16Z","updated_at":"2016-06-17T15:12:16Z","html_url":"https://github.com/sgmap/api-communes/pull/48#discussion_r67525980","pull_request_url":"https://api.github.com/repos/sgmap/api-communes/pulls/48","_links":{"self":{"href":"https://api.github.com/repos/sgmap/api-communes/pulls/comments/67525980"},"html":{"href":"https://github.com/sgmap/api-communes/pull/48#discussion_r67525980"},"pull_request":{"href":"https://api.github.com/repos/sgmap/api-communes/pulls/48"}}},"pull_request":{"url":"https://api.github.com/repos/sgmap/api-communes/pulls/48","id":74250189,"html_url":"https://github.com/sgmap/api-communes/pull/48","diff_url":"https://github.com/sgmap/api-communes/pull/48.diff","patch_url":"https://github.com/sgmap/api-communes/pull/48.patch","issue_url":"https://api.github.com/repos/sgmap/api-communes/issues/48","number":48,"state":"open","locked":false,"title":"Généralisation des helpers","user":{"login":"jdesboeufs","id":1231232,"avatar_url":"https://avatars.githubusercontent.com/u/1231232?v=3","gravatar_id":"","url":"https://api.github.com/users/jdesboeufs","html_url":"https://github.com/jdesboeufs","followers_url":"https://api.github.com/users/jdesboeufs/followers","following_url":"https://api.github.com/users/jdesboeufs/following{/other_user}","gists_url":"https://api.github.com/users/jdesboeufs/gists{/gist_id}","starred_url":"https://api.github.com/users/jdesboeufs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdesboeufs/subscriptions","organizations_url":"https://api.github.com/users/jdesboeufs/orgs","repos_url":"https://api.github.com/users/jdesboeufs/repos","events_url":"https://api.github.com/users/jdesboeufs/events{/privacy}","received_events_url":"https://api.github.com/users/jdesboeufs/received_events","type":"User","site_admin":false},"body":"Réutilisation accrue du code.\r\n\r\n3 helpers :\r\n* `initFields(options)` : construction d'un middleware qui initialise la liste des champs qui seront sérialisés en sortie. Prends 2 options obligatoires : `base` qui est la liste des champs toujours sérialisés et `default` qui est la liste par défaut quand elle n'est pas fournie dans la query-string.\r\n* `initFormat()` : permet de gérer les géométries dans le cas du GeoJSON. Prends deux options facultatives : `geometries` qui est la liste des géométries utilisables et `defaultGeometry`\r\n* `formatOne` : sérialise les données selon les paramètres présents dans l'objet `req`","created_at":"2016-06-17T14:22:06Z","updated_at":"2016-06-17T15:12:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a97fbfd48b3feee111e5b100e6d7f51989271acf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sgmap/api-communes/pulls/48/commits","review_comments_url":"https://api.github.com/repos/sgmap/api-communes/pulls/48/comments","review_comment_url":"https://api.github.com/repos/sgmap/api-communes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sgmap/api-communes/issues/48/comments","statuses_url":"https://api.github.com/repos/sgmap/api-communes/statuses/17baa6786ba3b8e5df3e3e48eb84648cec50baed","head":{"label":"sgmap:helpers","ref":"helpers","sha":"17baa6786ba3b8e5df3e3e48eb84648cec50baed","user":{"login":"sgmap","id":7874148,"avatar_url":"https://avatars.githubusercontent.com/u/7874148?v=3","gravatar_id":"","url":"https://api.github.com/users/sgmap","html_url":"https://github.com/sgmap","followers_url":"https://api.github.com/users/sgmap/followers","following_url":"https://api.github.com/users/sgmap/following{/other_user}","gists_url":"https://api.github.com/users/sgmap/gists{/gist_id}","starred_url":"https://api.github.com/users/sgmap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgmap/subscriptions","organizations_url":"https://api.github.com/users/sgmap/orgs","repos_url":"https://api.github.com/users/sgmap/repos","events_url":"https://api.github.com/users/sgmap/events{/privacy}","received_events_url":"https://api.github.com/users/sgmap/received_events","type":"Organization","site_admin":false},"repo":{"id":59763982,"name":"api-communes","full_name":"sgmap/api-communes","owner":{"login":"sgmap","id":7874148,"avatar_url":"https://avatars.githubusercontent.com/u/7874148?v=3","gravatar_id":"","url":"https://api.github.com/users/sgmap","html_url":"https://github.com/sgmap","followers_url":"https://api.github.com/users/sgmap/followers","following_url":"https://api.github.com/users/sgmap/following{/other_user}","gists_url":"https://api.github.com/users/sgmap/gists{/gist_id}","starred_url":"https://api.github.com/users/sgmap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgmap/subscriptions","organizations_url":"https://api.github.com/users/sgmap/orgs","repos_url":"https://api.github.com/users/sgmap/repos","events_url":"https://api.github.com/users/sgmap/events{/privacy}","received_events_url":"https://api.github.com/users/sgmap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sgmap/api-communes","description":"Rechercher des communes et accéder à leurs informations de base","fork":false,"url":"https://api.github.com/repos/sgmap/api-communes","forks_url":"https://api.github.com/repos/sgmap/api-communes/forks","keys_url":"https://api.github.com/repos/sgmap/api-communes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sgmap/api-communes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sgmap/api-communes/teams","hooks_url":"https://api.github.com/repos/sgmap/api-communes/hooks","issue_events_url":"https://api.github.com/repos/sgmap/api-communes/issues/events{/number}","events_url":"https://api.github.com/repos/sgmap/api-communes/events","assignees_url":"https://api.github.com/repos/sgmap/api-communes/assignees{/user}","branches_url":"https://api.github.com/repos/sgmap/api-communes/branches{/branch}","tags_url":"https://api.github.com/repos/sgmap/api-communes/tags","blobs_url":"https://api.github.com/repos/sgmap/api-communes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sgmap/api-communes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sgmap/api-communes/git/refs{/sha}","trees_url":"https://api.github.com/repos/sgmap/api-communes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sgmap/api-communes/statuses/{sha}","languages_url":"https://api.github.com/repos/sgmap/api-communes/languages","stargazers_url":"https://api.github.com/repos/sgmap/api-communes/stargazers","contributors_url":"https://api.github.com/repos/sgmap/api-communes/contributors","subscribers_url":"https://api.github.com/repos/sgmap/api-communes/subscribers","subscription_url":"https://api.github.com/repos/sgmap/api-communes/subscription","commits_url":"https://api.github.com/repos/sgmap/api-communes/commits{/sha}","git_commits_url":"https://api.github.com/repos/sgmap/api-communes/git/commits{/sha}","comments_url":"https://api.github.com/repos/sgmap/api-communes/comments{/number}","issue_comment_url":"https://api.github.com/repos/sgmap/api-communes/issues/comments{/number}","contents_url":"https://api.github.com/repos/sgmap/api-communes/contents/{+path}","compare_url":"https://api.github.com/repos/sgmap/api-communes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sgmap/api-communes/merges","archive_url":"https://api.github.com/repos/sgmap/api-communes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sgmap/api-communes/downloads","issues_url":"https://api.github.com/repos/sgmap/api-communes/issues{/number}","pulls_url":"https://api.github.com/repos/sgmap/api-communes/pulls{/number}","milestones_url":"https://api.github.com/repos/sgmap/api-communes/milestones{/number}","notifications_url":"https://api.github.com/repos/sgmap/api-communes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sgmap/api-communes/labels{/name}","releases_url":"https://api.github.com/repos/sgmap/api-communes/releases{/id}","deployments_url":"https://api.github.com/repos/sgmap/api-communes/deployments","created_at":"2016-05-26T15:59:05Z","updated_at":"2016-05-30T14:24:42Z","pushed_at":"2016-06-17T14:59:40Z","git_url":"git://github.com/sgmap/api-communes.git","ssh_url":"git@github.com:sgmap/api-communes.git","clone_url":"https://github.com/sgmap/api-communes.git","svn_url":"https://github.com/sgmap/api-communes","homepage":"https://api.gouv.fr/api/geoapi.html","size":147,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":20,"forks":0,"open_issues":20,"watchers":0,"default_branch":"master"}},"base":{"label":"sgmap:master","ref":"master","sha":"c2adf631edf8c486925ffd1b24e4b16718297430","user":{"login":"sgmap","id":7874148,"avatar_url":"https://avatars.githubusercontent.com/u/7874148?v=3","gravatar_id":"","url":"https://api.github.com/users/sgmap","html_url":"https://github.com/sgmap","followers_url":"https://api.github.com/users/sgmap/followers","following_url":"https://api.github.com/users/sgmap/following{/other_user}","gists_url":"https://api.github.com/users/sgmap/gists{/gist_id}","starred_url":"https://api.github.com/users/sgmap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgmap/subscriptions","organizations_url":"https://api.github.com/users/sgmap/orgs","repos_url":"https://api.github.com/users/sgmap/repos","events_url":"https://api.github.com/users/sgmap/events{/privacy}","received_events_url":"https://api.github.com/users/sgmap/received_events","type":"Organization","site_admin":false},"repo":{"id":59763982,"name":"api-communes","full_name":"sgmap/api-communes","owner":{"login":"sgmap","id":7874148,"avatar_url":"https://avatars.githubusercontent.com/u/7874148?v=3","gravatar_id":"","url":"https://api.github.com/users/sgmap","html_url":"https://github.com/sgmap","followers_url":"https://api.github.com/users/sgmap/followers","following_url":"https://api.github.com/users/sgmap/following{/other_user}","gists_url":"https://api.github.com/users/sgmap/gists{/gist_id}","starred_url":"https://api.github.com/users/sgmap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgmap/subscriptions","organizations_url":"https://api.github.com/users/sgmap/orgs","repos_url":"https://api.github.com/users/sgmap/repos","events_url":"https://api.github.com/users/sgmap/events{/privacy}","received_events_url":"https://api.github.com/users/sgmap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sgmap/api-communes","description":"Rechercher des communes et accéder à leurs informations de base","fork":false,"url":"https://api.github.com/repos/sgmap/api-communes","forks_url":"https://api.github.com/repos/sgmap/api-communes/forks","keys_url":"https://api.github.com/repos/sgmap/api-communes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sgmap/api-communes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sgmap/api-communes/teams","hooks_url":"https://api.github.com/repos/sgmap/api-communes/hooks","issue_events_url":"https://api.github.com/repos/sgmap/api-communes/issues/events{/number}","events_url":"https://api.github.com/repos/sgmap/api-communes/events","assignees_url":"https://api.github.com/repos/sgmap/api-communes/assignees{/user}","branches_url":"https://api.github.com/repos/sgmap/api-communes/branches{/branch}","tags_url":"https://api.github.com/repos/sgmap/api-communes/tags","blobs_url":"https://api.github.com/repos/sgmap/api-communes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sgmap/api-communes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sgmap/api-communes/git/refs{/sha}","trees_url":"https://api.github.com/repos/sgmap/api-communes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sgmap/api-communes/statuses/{sha}","languages_url":"https://api.github.com/repos/sgmap/api-communes/languages","stargazers_url":"https://api.github.com/repos/sgmap/api-communes/stargazers","contributors_url":"https://api.github.com/repos/sgmap/api-communes/contributors","subscribers_url":"https://api.github.com/repos/sgmap/api-communes/subscribers","subscription_url":"https://api.github.com/repos/sgmap/api-communes/subscription","commits_url":"https://api.github.com/repos/sgmap/api-communes/commits{/sha}","git_commits_url":"https://api.github.com/repos/sgmap/api-communes/git/commits{/sha}","comments_url":"https://api.github.com/repos/sgmap/api-communes/comments{/number}","issue_comment_url":"https://api.github.com/repos/sgmap/api-communes/issues/comments{/number}","contents_url":"https://api.github.com/repos/sgmap/api-communes/contents/{+path}","compare_url":"https://api.github.com/repos/sgmap/api-communes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sgmap/api-communes/merges","archive_url":"https://api.github.com/repos/sgmap/api-communes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sgmap/api-communes/downloads","issues_url":"https://api.github.com/repos/sgmap/api-communes/issues{/number}","pulls_url":"https://api.github.com/repos/sgmap/api-communes/pulls{/number}","milestones_url":"https://api.github.com/repos/sgmap/api-communes/milestones{/number}","notifications_url":"https://api.github.com/repos/sgmap/api-communes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sgmap/api-communes/labels{/name}","releases_url":"https://api.github.com/repos/sgmap/api-communes/releases{/id}","deployments_url":"https://api.github.com/repos/sgmap/api-communes/deployments","created_at":"2016-05-26T15:59:05Z","updated_at":"2016-05-30T14:24:42Z","pushed_at":"2016-06-17T14:59:40Z","git_url":"git://github.com/sgmap/api-communes.git","ssh_url":"git@github.com:sgmap/api-communes.git","clone_url":"https://github.com/sgmap/api-communes.git","svn_url":"https://github.com/sgmap/api-communes","homepage":"https://api.gouv.fr/api/geoapi.html","size":147,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":20,"forks":0,"open_issues":20,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sgmap/api-communes/pulls/48"},"html":{"href":"https://github.com/sgmap/api-communes/pull/48"},"issue":{"href":"https://api.github.com/repos/sgmap/api-communes/issues/48"},"comments":{"href":"https://api.github.com/repos/sgmap/api-communes/issues/48/comments"},"review_comments":{"href":"https://api.github.com/repos/sgmap/api-communes/pulls/48/comments"},"review_comment":{"href":"https://api.github.com/repos/sgmap/api-communes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sgmap/api-communes/pulls/48/commits"},"statuses":{"href":"https://api.github.com/repos/sgmap/api-communes/statuses/17baa6786ba3b8e5df3e3e48eb84648cec50baed"}}}}
{"actor":{"display_login":"jdesboeufs"}}