Skip to content

Commit

Permalink
feat: better mobile sync
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 committed Oct 25, 2024
1 parent 62e0658 commit 4291af8
Show file tree
Hide file tree
Showing 35 changed files with 3,120 additions and 16 deletions.
83 changes: 83 additions & 0 deletions e2e/src/api/specs/sync.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { LoginResponseDto, login, signUpAdmin } from '@immich/sdk';
import { loginDto, signupDto, uuidDto } from 'src/fixtures';
import { errorDto } from 'src/responses';
import { app, utils } from 'src/utils';
import request from 'supertest';
import { beforeAll, describe, expect, it } from 'vitest';

describe('/sync', () => {
let admin: LoginResponseDto;

beforeAll(async () => {
await utils.resetDatabase();
await signUpAdmin({ signUpDto: signupDto.admin });
admin = await login({ loginCredentialDto: loginDto.admin });
});

describe('GET /sync/acknowledge', () => {
it('should require authentication', async () => {
const { status, body } = await request(app).post('/sync/acknowledge');
expect(status).toBe(401);
expect(body).toEqual(errorDto.unauthorized);
});

it('should work', async () => {
const { status } = await request(app)
.post('/sync/acknowledge')
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({});
expect(status).toBe(204);
});

it('should work with an album sync date', async () => {
const { status } = await request(app)
.post('/sync/acknowledge')
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({
album: {
id: uuidDto.dummy,
timestamp: '2024-10-23T21:01:07.732Z',
},
});
expect(status).toBe(204);
});
});

describe('GET /sync/stream', () => {
it('should require authentication', async () => {
const { status, body } = await request(app).post('/sync/stream');
expect(status).toBe(401);
expect(body).toEqual(errorDto.unauthorized);
});

it('should require at least type', async () => {
const { status, body } = await request(app)
.post('/sync/stream')
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({ types: [] });
expect(status).toBe(400);
expect(body).toEqual(errorDto.badRequest());
});

it('should require valid types', async () => {
const { status, body } = await request(app)
.post('/sync/stream')
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({ types: ['invalid'] });
expect(status).toBe(400);
expect(body).toEqual(
errorDto.badRequest([expect.stringContaining('each value in types must be one of the following values')]),
);
});

it('should accept a valid type', async () => {
const response = await request(app)
.post('/sync/stream')
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({ types: ['asset'] });
expect(response.status).toBe(200);
expect(response.get('Content-Type')).toBe('application/jsonlines+json; charset=utf-8');
expect(response.body).toEqual('');
});
});
});
1 change: 1 addition & 0 deletions e2e/src/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const uuidDto = {
invalid: 'invalid-uuid',
// valid uuid v4
notFound: '00000000-0000-4000-a000-000000000000',
dummy: '00000000-0000-4000-a000-000000000000',
};

const adminLoginDto = {
Expand Down
10 changes: 10 additions & 0 deletions mobile/openapi/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions mobile/openapi/lib/api.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions mobile/openapi/lib/api/sync_api.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions mobile/openapi/lib/api_client.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions mobile/openapi/lib/api_helper.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions mobile/openapi/lib/model/album_asset_response_dto.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4291af8

Please sign in to comment.