feat(learn): Add test for file metadata project (#39625)

* Add tests

* Switch from local file to CDN

* remove extraneous declaration

* Apply review suggestions
This commit is contained in:
Nicholas Carrigan
2020-09-23 20:21:09 -07:00
committed by GitHub
parent e206907503
commit f132f5157c

View File

@ -6,6 +6,7 @@ forumTopicId: 301506
---
## Description
<section id='description'>
Build a full stack JavaScript app that is functionally similar to this: <a href='https://file-metadata.freecodecamp.repl.co/' target='_blank'>https://file-metadata.freecodecamp.repl.co/</a>.
Working on this project will involve you writing your code on Repl.it on our starter project. After completing this project you can copy your public Repl.it URL (to the homepage of your app) into this screen to test it! Optionally you may choose to write your project on another platform but it must be publicly visible for our testing.
@ -13,32 +14,62 @@ Start this project on Repl.it using <a href='https://repl.it/github/freeCodeCamp
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: I can provide my own project, not the example URL.
testString: "getUserInput => {
assert(!(new RegExp('.*/file-metadata.freecodecamp.repl.co')).test(getUserInput('url')));
}"
- text: I can submit a form that includes a file upload.
testString: ''
testString: "async getUserInput => {
const site = await fetch(getUserInput('url'));
const data = await site.text();
const doc = new DOMParser().parseFromString(data, 'text/html');
assert(doc.querySelector('input[type=\"file\"]'));
}"
- text: The form file input field has the <code>name</code> attribute set to <code>upfile</code>.
testString: ''
testString: "async getUserInput => {
const site = await fetch(getUserInput('url'));
const data = await site.text();
const doc = new DOMParser().parseFromString(data, 'text/html');
assert(doc.querySelector('input[name=\"upfile\"]'));
}"
- text: When I submit something, I will receive the file <code>name</code>, <code>type</code>, and <code>size</code> in bytes within the JSON response.
testString: ''
testString: "async getUserInput => {
const formData = new FormData();
const fileData = await fetch('https://cdn.freecodecamp.org/weather-icons/01d.png');
const file = await fileData.blob();
formData.append('upfile', file, 'icon');
const data = await fetch(getUserInput('url') + '/api/fileanalyse', {
method: 'POST', body: formData
});
const parsed = await data.json();
assert.property(parsed, 'size');
assert.equal(parsed.name, 'icon');
assert.equal(parsed.type, 'image/png');
}"
```
</section>
## Challenge Seed
<section id='challengeSeed'>
</section>
## Solution
<section id='solution'>
```js