Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#172621882] Get all data for a specific user #42

Merged
merged 29 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
88113b6
update libs
balanza May 7, 2020
72a3437
implemented SetUserDataProcessingStatusActivityHandler
balanza May 7, 2020
42d6145
Merge branch 'master' into 172621882-accesso-ai-dati
balanza May 8, 2020
1cab5c3
ExtractUserDataActivity
balanza May 11, 2020
a497dbb
better comments
balanza May 11, 2020
ff9a056
better failure handling
balanza May 11, 2020
3b800f8
fix exhaustive check
balanza May 11, 2020
691b857
fix lint
balanza May 11, 2020
87d4032
refactor
balanza May 11, 2020
1febd9a
retrieving notifications using message id
balanza May 12, 2020
6a5092b
fix comments
balanza May 12, 2020
98dd1f4
add query notification status
balanza May 12, 2020
31a6259
message blobs as separate entities
balanza May 12, 2020
e2b542c
use t.exact instead of manually skims types
balanza May 12, 2020
a876b03
refactor sequences
balanza May 12, 2020
975e3e5
using flatten
balanza May 12, 2020
4b0cf46
avoid extract webhook urls
balanza May 12, 2020
0bd30e8
refactor
balanza May 13, 2020
e6cdd0f
Update ExtractUserDataActivity/index.ts
balanza May 13, 2020
bffd99e
Merge branch '172621882-accesso-ai-dati' of github.com:pagopa/io-func…
balanza May 13, 2020
c4fb9ae
using bimap
balanza May 13, 2020
caf973f
Update ExtractUserDataActivity/handler.ts
balanza May 13, 2020
daadc33
Update ExtractUserDataActivity/notification.ts
balanza May 13, 2020
ab9cd6b
Update ExtractUserDataActivity/handler.ts
balanza May 13, 2020
44ce7be
Update ExtractUserDataActivity/handler.ts
balanza May 13, 2020
3b55c55
refactor
balanza May 13, 2020
36d8728
Merge branch '172621882-accesso-ai-dati' of github.com:pagopa/io-func…
balanza May 13, 2020
eec952f
refactor
balanza May 13, 2020
919c475
added message status to export
balanza May 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions ExtractUserDataActivity/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/* tslint:disable: no-any */

import { Either, right } from "fp-ts/lib/Either";
import { fromNullable, Option, some } from "fp-ts/lib/Option";

import { context as contextMock } from "../../__mocks__/durable-functions";
import {
aFiscalCode,
aProfile,
aRetrievedMessageStatus,
aRetrievedNotificationStatus
} from "../../__mocks__/mocks";

import {
ActivityInput,
ActivityResultSuccess,
createExtractUserDataActivityHandler
} from "../handler";

import { BlobService } from "azure-storage";
import { QueryError } from "documentdb";
import { MessageModel } from "io-functions-commons/dist/src/models/message";
import { MessageStatusModel } from "io-functions-commons/dist/src/models/message_status";
import { NotificationStatusModel } from "io-functions-commons/dist/src/models/notification_status";
import { ProfileModel } from "io-functions-commons/dist/src/models/profile";
import { SenderServiceModel } from "io-functions-commons/dist/src/models/sender_service";
import { readableReport } from "italia-ts-commons/lib/reporters";
import {
aMessageContent,
aRetrievedMessageWithoutContent,
aRetrievedNotification,
aRetrievedSenderService,
aRetrievedWebhookNotification
} from "../../__mocks__/mocks";
import { NotificationModel } from "../notification"; // we use the local-defined model

const createMockIterator = <T>(a: ReadonlyArray<T>) => {
const data = Array.from(a);
return {
async executeNext(): Promise<Either<QueryError, Option<readonly T[]>>> {
const next = data.shift();
return right(fromNullable(next ? [next] : undefined));
}
};
};

const messageModelMock = ({
findMessages: jest.fn(() =>
createMockIterator([aRetrievedMessageWithoutContent])
),
getContentFromBlob: jest.fn(async () => right(some(aMessageContent)))
} as any) as MessageModel;

const messageStatusModelMock = ({
findOneByMessageId: jest.fn(async () => right(some(aRetrievedMessageStatus)))
} as any) as MessageStatusModel;

const senderServiceModelMock = ({
findSenderServicesForRecipient: jest.fn(() =>
createMockIterator([aRetrievedSenderService])
)
} as any) as SenderServiceModel;

const profileModelMock = ({
findOneProfileByFiscalCode: jest.fn(async () => right(some(aProfile)))
} as any) as ProfileModel;

const notificationModelMock = ({
findNotificationsForMessage: jest.fn(() =>
createMockIterator([aRetrievedNotification])
)
} as any) as NotificationModel;

const notificationStatusModelMock = ({
findOneNotificationStatusByNotificationChannel: jest.fn(async () =>
right(some(aRetrievedNotificationStatus))
)
} as any) as NotificationStatusModel;

const blobServiceMock = ({} as any) as BlobService;

describe("createExtractUserDataActivityHandler", () => {
it("should handle export for existing user", async () => {
const handler = createExtractUserDataActivityHandler(
messageModelMock,
messageStatusModelMock,
notificationModelMock,
notificationStatusModelMock,
profileModelMock,
senderServiceModelMock,
blobServiceMock
);
const input: ActivityInput = {
fiscalCode: aFiscalCode
};

const result = await handler(contextMock, input);

result.fold(
response => fail(`Failing result, response: ${JSON.stringify(response)}`),
response => {
ActivityResultSuccess.decode(response).fold(
err =>
fail(`Failing decoding result, response: ${readableReport(err)}`),
e => expect(e.kind).toBe("SUCCESS")
);
}
);
});

it("should not export webhook notification data", async () => {
const notificationWebhookModelMock = ({
findNotificationsForMessage: jest.fn(() =>
createMockIterator([aRetrievedWebhookNotification])
)
} as any) as NotificationModel;

const handler = createExtractUserDataActivityHandler(
messageModelMock,
messageStatusModelMock,
notificationWebhookModelMock,
notificationStatusModelMock,
profileModelMock,
senderServiceModelMock,
blobServiceMock
);
const input: ActivityInput = {
fiscalCode: aFiscalCode
};

const result = await handler(contextMock, input);

result.fold(
response => fail(`Failing result, response: ${JSON.stringify(response)}`),
response => {
ActivityResultSuccess.decode(response).fold(
err =>
fail(`Failing decoding result, response: ${readableReport(err)}`),
e => expect(e.value.notifications[0].channels.WEBHOOK).toEqual({})
);
}
);
});

it("should query using correct data", async () => {
const handler = createExtractUserDataActivityHandler(
messageModelMock,
messageStatusModelMock,
notificationModelMock,
notificationStatusModelMock,
profileModelMock,
senderServiceModelMock,
blobServiceMock
);
const input: ActivityInput = {
fiscalCode: aFiscalCode
};

await handler(contextMock, input);

expect(messageModelMock.getContentFromBlob).toHaveBeenCalledWith(
blobServiceMock,
aRetrievedMessageWithoutContent.id
);
expect(messageModelMock.findMessages).toHaveBeenCalledWith(aFiscalCode);
expect(messageStatusModelMock.findOneByMessageId).toHaveBeenCalledWith(
aRetrievedMessageWithoutContent.id
);
expect(
notificationModelMock.findNotificationsForMessage
).toHaveBeenCalledWith(aRetrievedMessageWithoutContent.id);
expect(
notificationStatusModelMock.findOneNotificationStatusByNotificationChannel
).toHaveBeenCalledWith(aRetrievedNotification.id, "WEBHOOK");
expect(
notificationStatusModelMock.findOneNotificationStatusByNotificationChannel
).toHaveBeenCalledWith(aRetrievedNotification.id, "EMAIL");
expect(
senderServiceModelMock.findSenderServicesForRecipient
).toHaveBeenCalledWith(aFiscalCode);
});
});
10 changes: 10 additions & 0 deletions ExtractUserDataActivity/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"bindings": [
{
"name": "name",
"type": "activityTrigger",
"direction": "in"
}
],
"scriptFile": "../dist/ExtractUserDataActivity/index.js"
}
Loading