Skip to content

Commit

Permalink
feat(#1): compiled, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed May 17, 2024
1 parent 14ef3f4 commit 68f0eb0
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/compiled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 Aliaksei Bialiauski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Compile full GitHub search query.
* @param {String} search Search query
* @param {String} type Date type
* @param {String} start Start date
* @param {String} end End date
* @return {String} Compiled query
*/
const compiled = function(search, type, start, end) {
return `${search} ${type}:${start}..${end}`
};

module.exports = compiled;
39 changes: 39 additions & 0 deletions test/compiled.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 Aliaksei Bialiauski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
const assert = require('assert');
const compiled = require('../src/compiled.js');

describe('Test case for compiled.js', function() {
it('compiles query from parts', function() {
const query = compiled(
'stars:1..100', 'pushed', '2023-01-01', '2024-01-01'
);
const expected = 'stars:1..100 pushed:2023-01-01..2024-01-01';
assert.equal(
query,
expected,
`compiled query ${query} does not match with expected ${expected}`
);
});
});

0 comments on commit 68f0eb0

Please sign in to comment.