Skip to content

Commit

Permalink
Switch tests to use new file urls
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed Jan 24, 2024
1 parent 9e3a6e1 commit 8d247b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
20 changes: 8 additions & 12 deletions test/file.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { faker } from '@faker-js/faker';
import { bufferFromStream } from '@seedcompany/common';
import got from 'got';
import { startCase, times } from 'lodash';
import {
DateTime,
Expand Down Expand Up @@ -104,14 +104,10 @@ function resetNow() {
Settings.now = () => Date.now();
}

const expectEqualContent = async (
bucket: LocalBucket,
url: string,
expected: FakeFile,
) => {
const actualFile = await bucket.download(url);
const contents = await bufferFromStream(actualFile.Body);
expect(contents.toString()).toEqual(expected.content.toString());
const expectEqualContent = async (url: string, expected: FakeFile) => {
const expectedContents = expected.content.toString();
const actualContents = await got(url).buffer();
expect(expectedContents).toEqual(actualContents);
};

describe('File e2e', () => {
Expand Down Expand Up @@ -157,7 +153,7 @@ describe('File e2e', () => {
expect(modifiedAt.diffNow().as('seconds')).toBeGreaterThan(-30);
const createdAt = DateTime.fromISO(file.createdAt);
expect(createdAt.diffNow().as('seconds')).toBeGreaterThan(-30);
await expectEqualContent(bucket, file.downloadUrl, fakeFile);
await expectEqualContent(file.url, fakeFile);
expect(file.parents[0].id).toEqual(root.id);
}
});
Expand All @@ -178,7 +174,7 @@ describe('File e2e', () => {
expect(version.createdBy.id).toEqual(me.id);
const createdAt = DateTime.fromISO(version.createdAt);
expect(createdAt.diffNow().as('seconds')).toBeGreaterThan(-30);
await expectEqualContent(bucket, file.downloadUrl, fakeFile);
await expectEqualContent(file.url, fakeFile);
expect(version.parents[0].id).toEqual(file.id);
});

Expand Down Expand Up @@ -217,7 +213,7 @@ describe('File e2e', () => {
input: FakeFile,
) {
expect(updated.id).toEqual(initial.id);
await expectEqualContent(bucket, updated.downloadUrl, input);
await expectEqualContent(updated.url, input);
expect(updated.size).toEqual(input.size);
expect(updated.mimeType).toEqual(input.mimeType);
const createdAt = DateTime.fromISO(updated.createdAt);
Expand Down
6 changes: 3 additions & 3 deletions test/utility/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,12 @@ export const fileNode = gql`
... on FileVersion {
mimeType
size
downloadUrl
url
}
... on File {
mimeType
size
downloadUrl
url
modifiedAt
modifiedBy {
...user
Expand All @@ -421,7 +421,7 @@ export type RawBaseFileNode = RawNode<
>;
export type RawDirectory = RawBaseFileNode;
export type RawFileVersion = RawBaseFileNode &
RawNode<FileVersion, keyof IFileNode, { downloadUrl: string }>;
RawNode<FileVersion, keyof IFileNode, { url: string }>;
export type RawFile = RawFileVersion &
RawNode<
File,
Expand Down

0 comments on commit 8d247b7

Please sign in to comment.