Response.test.js 3.0 KB

1234567891011121314151617181920212223
  1. import Collection from '../../../src/lib/DAV/Collection';
  2. import Response from '../../../src/lib/DAV/Response';
  3. describe('Response', () => {
  4. const responseText = `<?xml version="1.0" encoding="utf-8"?><D:multistatus xmlns:D="DAV:"><D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/"><D:href>/path/to/</D:href><D:propstat><D:prop><lp1:resourcetype><D:collection/></lp1:resourcetype><lp1:creationdate>2019-11-07T10:40:00Z</lp1:creationdate><lp1:getlastmodified>Thu, 07 Nov 2019 10:40:00 GMT</lp1:getlastmodified><lp1:getetag>"23-596bf4994c6f6"</lp1:getetag><D:supportedlock><D:lockentry><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry><D:lockentry><D:lockscope><D:shared/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock><D:lockdiscovery/><D:getcontenttype>httpd/unix-directory</D:getcontenttype></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response><D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/"><D:href>/path/to/file</D:href><D:propstat><D:prop><lp1:resourcetype/><lp1:creationdate>2019-11-07T10:39:54Z</lp1:creationdate><lp1:getcontentlength>0</lp1:getcontentlength><lp1:getlastmodified>Thu, 07 Nov 2019 10:39:54 GMT</lp1:getlastmodified><lp1:getetag>"0-596bf4936570f"</lp1:getetag><lp2:executable>F</lp2:executable><D:supportedlock><D:lockentry><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry><D:lockentry><D:lockscope><D:shared/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock><D:lockdiscovery/></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response><D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/"><D:href>/path/to/directory/</D:href><D:propstat><D:prop><lp1:resourcetype><D:collection/></lp1:resourcetype><lp1:creationdate>2019-11-07T10:40:00Z</lp1:creationdate><lp1:getlastmodified>Thu, 07 Nov 2019 10:40:00 GMT</lp1:getlastmodified><lp1:getetag>"6-596bf4994c6f6"</lp1:getetag><D:supportedlock><D:lockentry><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry><D:lockentry><D:lockscope><D:shared/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock><D:lockdiscovery/><D:getcontenttype>httpd/unix-directory</D:getcontenttype></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response></D:multistatus>`,
  5. response = new Response(responseText)
  6. ;
  7. it('should return a valid Collection object that contains the expected entries', () => {
  8. const collection = response.collection(),
  9. entries = collection.map((entry) => entry),
  10. [, directory, file] = entries
  11. ;
  12. expect(collection).toBeInstanceOf(Collection);
  13. expect(collection.path).toBe('/path/to');
  14. expect(entries.length).toBe(3);
  15. expect(directory.directory).toBeTrue();
  16. expect(directory.title).toBe('directory');
  17. expect(file.directory).toBeFalse();
  18. expect(file.title).toBe('file');
  19. });
  20. });