diff --git a/Info.md b/Info.md new file mode 100644 index 0000000..d654073 --- /dev/null +++ b/Info.md @@ -0,0 +1,20 @@ +https://www.microsoft.com/en-us/dev-community/Event/Register?eventId=GitHubCopilotHackathonSwitzerland-June20th2023_TkUYX_Ms_SmQ&ocid=aid3054457 + +# Romano Roth + +Name the files with the goal you want to achieve. +6K chars limits. +Open only the relevant files. + +# Github guy - +coplilot chat - When done? +copilot for PR for ADO - GH +copilot for docs - Which integration are available ETA + +Data is destroyed streight away after the code has been generated. + +# Microsoft CodeSpaces - Emanuele Bartolesi +- share dev links to test - Adjast visibility + + +# Arito Marina - Pre-requisites \ No newline at end of file diff --git a/README.md b/README.md index 279ba54..9e170a0 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# Activate GitHub Copilot using Nodejs and .NET +****# Activate GitHub Copilot using Nodejs and .NET Demo project for running labs to evaluate Copilot viability - [Goal](#goal) - [Pre-requisites](#pre-requisites) - [Work with Github Codespaces](#work-with-github-codespaces) -- [Work locally](#work-locally) + - [Work locally](#work-locally) - [Instructions](#instructions) ## Goal diff --git a/exercisefiles/node/NodeServer.js b/exercisefiles/node/NodeServer.js new file mode 100644 index 0000000..2f4ba70 --- /dev/null +++ b/exercisefiles/node/NodeServer.js @@ -0,0 +1,104 @@ +// write a nodejs server that will expose a method call "get" that will return the value of the key passed in the query string +// example: http://localhost:3000/get?key=hello +// if the key is not passed, return "key not passed" +// if the key is passed, return "hello" + key +// if the url has other methods, return "method not supported" +// when server is listening, log "server is listening on port 3000" + +var http = require('http'); +var url = require('url'); +var axios = require('axios'); + +// write a function to return a joke using axios +// use the url https://api.chucknorris.io/jokes/random + +function getJoke() { + return axios.get('https://api.chucknorris.io/jokes/random') + .then(function (response) { + // console.log(response.data.value); + return response.data.value; + }) + .catch(function (error) { + // console.log(error); + return error + }); +} + +http.createServer(function (req, res) { + var q = url.parse(req.url, true); + +// Update the code below to return the days between 2 dates passed in the query string checking the key to verify that 2 dates are passed +// example: http://localhost:3000/get?key=2018-01-01,2018-01-03 +// should return 2 + +// write a function to verify that the 2 dates are passed in the key separated by a comma + + + + if (q.pathname === '/get') { + if (q.query.key) { + var colors = require('./colors.json'); + var color = colors.find(function (color) { + return color.color === q.query.key; + }); + function checkIfDates(key) { + var dates = key.split(','); + if (dates.length === 2) { + return true; + } + } + if (color) { + res.writeHead(200, { 'Content-Type': 'text/html' }); + console.log(color.code.hex); + res.write(color.code.hex); //hexString); + res.end(); + } else if (checkIfDates(q.query.key)) { + var date1 = new Date(q.query.key.split(',')[0]); + var date2 = new Date(q.query.key.split(',')[1]); + var diff = Math.abs(date1.getTime() - date2.getTime()); + var diffDays = Math.ceil(diff / (1000 * 3600 * 24)); + res.writeHead(200, { 'Content-Type': 'text/html' }); + if (diffDays === 999) { + res.write('Tombola'); + res.end(); + } else { + res.write(diffDays.toString()); + res.end(); + } + } else { + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.write('hello ' + q.query.key); + res.end(); + } + } + else { + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.write('key not passed'); + res.end(); + } + } + else if (q.pathname === '/TellMeAJoke') { + getJoke() + .then(function (joke) { + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.write(joke); + res.end(); + }) + .catch(function (error) { + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.write(error); + res.end(); + }); + } else { + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.write('method not supported'); + res.end(); + } +} + +).listen(3000, function () { + console.log('server is listening on port 3000'); +} +); + + diff --git a/exercisefiles/node/getJoke.js b/exercisefiles/node/getJoke.js new file mode 100644 index 0000000..80e146c --- /dev/null +++ b/exercisefiles/node/getJoke.js @@ -0,0 +1,27 @@ +var axios = require('axios'); + +function getJoke() { + axios.get('https://api.chucknorris.io/jokes/random') + .then(function (response) { + console.log(response.data.value); + // return response.data.value; + }) + .catch(function (error) { + console.log(error); + // return error + }); +} + +function getJoke2() { + axios.get('https://api.chucknorris.io/jokes/random') + .then(function (response) { + console.log(response.data.value); + // return response.data.value; + }) + .catch(function (error) { + console.log(error); + // return error + }); +} +// getJoke(); +getJoke2(); \ No newline at end of file diff --git a/exercisefiles/node/nodeserver.js b/exercisefiles/node/nodeserver.js deleted file mode 100644 index f68e5b8..0000000 --- a/exercisefiles/node/nodeserver.js +++ /dev/null @@ -1,7 +0,0 @@ -// write a nodejs server that will expose a method call "get" that will return the value of the key passed in the query string -// example: http://localhost:3000/get?key=hello -// if the key is not passed, return "key not passed" -// if the key is passed, return "hello" + key -// if the url has other methods, return "method not supported" -// when server is listening, log "server is listening on port 3000" - diff --git a/exercisefiles/node/test.js b/exercisefiles/node/test.js index de5fab8..d6d8446 100644 --- a/exercisefiles/node/test.js +++ b/exercisefiles/node/test.js @@ -10,7 +10,6 @@ const http = require('http'); const server = require('./NodeServer'); - describe('Node Server', () => { it('should return "key not passed" if key is not passed', (done) => { http @@ -25,19 +24,227 @@ describe('Node Server', () => { }); }); }); +}); - //add test to check get when key is equal to world - //add test to check validatephoneNumber - //write test to validate validateSpanishDNI - +//add test to check get when key is equal to world + +describe('Node Server', () => { + it('should return "hello world" if key is equal to world', (done) => { + http + .get('http://localhost:3000/get?key=world' , (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { + assert.equal(data, 'hello world'); + done(); + }); + }); + }); +}); - //write test for returnColorCode red should return code #FF0000 - //write test for daysBetweenDates +//add test to check get when a phonenumber is passed and call +describe('Node Server', () => { + it('should return "phone number is valid" if phonenumber is valid', (done) => { + http + .get('http://localhost:3000/get?key=1234567890' , (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { + assert.equal(data, 'hello 1234567890'); + done(); + }); + }); + }); +}); +//add test to check get when a phonenumber Zurich/Switzerland number is passed to the call -}); \ No newline at end of file +describe('Node Server', () => { + it('should return "phone number is valid" if phonenumber is valid', (done) => { + http.get('http://localhost:3000/get?key=0441234567', (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { + assert.equal(data, 'hello 0441234567'); + done(); + }); + }); + }); +}); + +//add test to check get when a phonenumber Zurich/Switzerland number is passed to the call +// what the ascii char for the sign + + + +describe('Node Server', () => { + it('should return "phone number is valid" if phonenumber is valid', (done) => { + http.get('http://localhost:3000/get?key=%2B41441234567', (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { + assert.equal(data, 'hello +41441234567'); + done(); + }); + }); + } + ); +}); + +//add a test that a valida validateSpanishDNI is passed to the Node Server + +describe('Node Server', () => { + it('should return "DNI is valid" if DNI is valid', (done) => { + http.get('http://localhost:3000/get?key=12345678z', (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { + assert.equal(data, 'hello 12345678z'); + done(); + }); + }); + } + ); +}); + +//write test for returnColorCode red should return code #FF0000 + +describe('Node Server', () => { + it('should return "#FF0000" if color is red', (done) => { + http.get('http://localhost:3000/get?key=red', (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { + assert.equal(data, '#FF0000'); + done(); + }); + }); + } + ); +}); + +//write test for returnColorCode blue should return code #0000FF + +describe('Node Server', () => { + it('should return "#0000FF" if color is blue', (done) => { + http.get('http://localhost:3000/get?key=blue', (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { + assert.equal(data, '#0000FF'); + done(); + }); + }); + } + ); +}); + +// //write test for returnColorCode green should return code #00FF00 +describe('Node Server', () => { + it('should return "#00FF00" if color is green', (done) => { + http.get('http://localhost:3000/get?key=green', (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { + assert.equal(data, '#00FF00'); + done(); + }); + }); + } + ); +}); + +//write test for returnColorCode yellow should return code #FFFF00 + +describe('Node Server', () => { + it('should return "#FFFF00" if color is yellow', (done) => { + http.get('http://localhost:3000/get?key=yellow', (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { + assert.equal(data, '#FFFF00'); + done(); + }); + }); + } + ); +}); + +//write test for returnColorCode black should return code #000000 + +describe('Node Server', () => { + it('should return "#000000" if color is black', (done) => { + http.get('http://localhost:3000/get?key=black', (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + }); + res.on('end', () => { + assert.equal(data, '#000000'); + done(); + }); + }); + } + ); +}); + +// write test for to verify that the days between 2 days are returned + +describe('Node Server', () => { + it('should return "2" if 2 days are passed', (done) => { + http.get('http://localhost:3000/get?key=2018-01-01,2018-01-03', (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + console.log(data); + }); + res.on('end', () => { + assert.equal(data, '2'); + done(); + }); + }); + } + ); +}); + +// write a test case to verify if I pass 2 dates with a difference of 999 days I get the message Tombola + +describe('Node Server', () => { + it('should return "Tombola" if 999 days are passed', (done) => { + http.get('http://localhost:3000/get?key=2018-01-01,2020-09-26', (res) => { + let data = ''; + res.on('data', (chunk) => { + data += chunk; + console.log(data); + }); + res.on('end', () => { + assert.equal(data, 'Tombola'); + done(); + }); + }); + } + ); +} +); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..c7c9fd6 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,102 @@ +{ + "name": "CopilotHackathon", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "axios": "^1.4.0" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/axios": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", + "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..cb17ec7 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "axios": "^1.4.0" + } +} diff --git a/swiss-ahv-number-test.js b/swiss-ahv-number-test.js new file mode 100644 index 0000000..e0d7511 --- /dev/null +++ b/swiss-ahv-number-test.js @@ -0,0 +1,15 @@ +// Create an unit test for this function validateSwissAhvNumber + +// Path: swiss-ahv-number-test.js + +const assert = require('assert'); +const validateSwissAhvNumber = require('./swiss-ahv-number'); + +describe('validateSwissAhvNumber', () => { + it('should return true if the number is valid', () => { + assert.equal(validateSwissAhvNumber('756.1234.5678.97'), true); + }); + it('should return false if the number is not valid', () => { + assert.equal(validateSwissAhvNumber('756.1234.5678.9'), false); + }); +} \ No newline at end of file diff --git a/swiss-ahv-number.js b/swiss-ahv-number.js new file mode 100644 index 0000000..1b53a78 --- /dev/null +++ b/swiss-ahv-number.js @@ -0,0 +1,8 @@ +// Create a function to validate a swiss ahv number using regex +// and return true if the number is valid and false if not. + +function validateSwissAhvNumber(number) { + const regex = /^(756\.)(\d{4}\.){2}\d{3}$/; + return regex.test(number); +} +