|
9 | 9 |
|
10 | 10 | let(:current_user) { build(:user, role: :standard) } |
11 | 11 |
|
| 12 | + before do |
| 13 | + form.set_task_status_service(task_status_service) |
| 14 | + end |
| 15 | + |
12 | 16 | describe "statuses" do |
13 | 17 | describe "name status" do |
14 | 18 | let(:form) { build(:form, :new_form, :with_group, group:) } |
|
391 | 395 | end |
392 | 396 | end |
393 | 397 | end |
| 398 | + |
| 399 | + describe "make_only_english_live_status" do |
| 400 | + let(:can_make_english_live) { false } |
| 401 | + let(:can_make_welsh_live) { false } |
| 402 | + |
| 403 | + let(:form) { build(:form, :with_group, group:) } |
| 404 | + |
| 405 | + before do |
| 406 | + allow(form).to receive(:can_make_language_live?).with(language: "en").and_return(can_make_english_live) |
| 407 | + allow(form).to receive(:can_make_language_live?).with(language: "cy").and_return(can_make_welsh_live) |
| 408 | + end |
| 409 | + |
| 410 | + context "with a new form" do |
| 411 | + let(:form) { build(:form, :new_form, :with_group, group:) } |
| 412 | + |
| 413 | + it "returns the correct default value" do |
| 414 | + expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :cannot_start |
| 415 | + end |
| 416 | + end |
| 417 | + |
| 418 | + context "when the English version can be made live" do |
| 419 | + let(:can_make_english_live) { true } |
| 420 | + |
| 421 | + it "returns not started" do |
| 422 | + expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :not_started |
| 423 | + end |
| 424 | + end |
| 425 | + |
| 426 | + context "when the English version cannot be made live" do |
| 427 | + let(:can_make_english_live) { false } |
| 428 | + |
| 429 | + context "when the form is live" do |
| 430 | + let(:form) { build(:form, :live, :with_group, group:) } |
| 431 | + |
| 432 | + it "returns completed" do |
| 433 | + expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :completed |
| 434 | + end |
| 435 | + end |
| 436 | + |
| 437 | + context "when the form is a draft" do |
| 438 | + let(:form) { build(:form, :ready_for_live, :with_group, group:) } |
| 439 | + |
| 440 | + it "returns cannot_start" do |
| 441 | + expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :cannot_start |
| 442 | + end |
| 443 | + end |
| 444 | + |
| 445 | + context "when the form is live with draft" do |
| 446 | + let(:form) { build(:form, :live_with_draft, :with_group, group:) } |
| 447 | + |
| 448 | + it "returns cannot_start" do |
| 449 | + expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :cannot_start |
| 450 | + end |
| 451 | + end |
| 452 | + |
| 453 | + context "when the form is archived" do |
| 454 | + let(:form) { build(:form, :archived, :with_group, group:) } |
| 455 | + |
| 456 | + it "returns cannot_start" do |
| 457 | + expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :cannot_start |
| 458 | + end |
| 459 | + end |
| 460 | + |
| 461 | + context "when the form is archived with draft" do |
| 462 | + let(:form) { build(:form, :archived_with_draft, :with_group, group:) } |
| 463 | + |
| 464 | + it "returns cannot_start" do |
| 465 | + expect(task_status_service.all_task_statuses[:make_only_english_live_status]).to eq :cannot_start |
| 466 | + end |
| 467 | + end |
| 468 | + end |
| 469 | + end |
| 470 | + |
| 471 | + describe "make_only_welsh_live_status" do |
| 472 | + let(:can_make_english_live) { true } |
| 473 | + let(:can_make_welsh_live) { false } |
| 474 | + |
| 475 | + let(:form) { build(:form, :with_group, group:) } |
| 476 | + |
| 477 | + before do |
| 478 | + allow(form).to receive(:can_make_language_live?).with(language: "en").and_return(can_make_english_live) |
| 479 | + allow(form).to receive(:can_make_language_live?).with(language: "cy").and_return(can_make_welsh_live) |
| 480 | + end |
| 481 | + |
| 482 | + context "with a new form" do |
| 483 | + let(:form) { build(:form, :new_form, :with_group, group:) } |
| 484 | + |
| 485 | + it "returns the correct default value" do |
| 486 | + expect(task_status_service.all_task_statuses[:make_only_welsh_live_status]).to eq :cannot_start |
| 487 | + end |
| 488 | + end |
| 489 | + |
| 490 | + context "when the Welsh version can be made live" do |
| 491 | + let(:can_make_welsh_live) { true } |
| 492 | + |
| 493 | + it "returns not started" do |
| 494 | + expect(task_status_service.all_task_statuses[:make_only_welsh_live_status]).to eq :not_started |
| 495 | + end |
| 496 | + end |
| 497 | + |
| 498 | + context "when the Welsh version cannot be made live" do |
| 499 | + let(:can_make_welsh_live) { false } |
| 500 | + let(:welsh_form_document) { build(:form_document, :live, form:, language: "cy", content: form.as_form_document) } |
| 501 | + |
| 502 | + before do |
| 503 | + allow(form).to receive(:live_welsh_form_document).and_return(welsh_form_document) |
| 504 | + end |
| 505 | + |
| 506 | + context "when the form already has a live Welsh version" do |
| 507 | + it "returns completed" do |
| 508 | + expect(task_status_service.all_task_statuses[:make_only_welsh_live_status]).to eq :completed |
| 509 | + end |
| 510 | + end |
| 511 | + |
| 512 | + context "when the form does not have a live Welsh version" do |
| 513 | + let(:welsh_form_document) { nil } |
| 514 | + |
| 515 | + it "returns cannot start" do |
| 516 | + expect(task_status_service.all_task_statuses[:make_only_welsh_live_status]).to eq :cannot_start |
| 517 | + end |
| 518 | + end |
| 519 | + end |
| 520 | + end |
394 | 521 | end |
395 | 522 |
|
396 | 523 | describe "#mandatory_tasks_completed" do |
|
537 | 664 | share_preview_status: :completed, |
538 | 665 | submission_email_status: :completed, |
539 | 666 | confirm_submission_email_status: :completed, |
| 667 | + make_only_english_live_status: :completed, |
| 668 | + make_only_welsh_live_status: :cannot_start, |
540 | 669 | } |
541 | 670 | expect(task_status_service.all_task_statuses).to eq expected_hash |
542 | 671 | end |
|
0 commit comments